Code Room
CodingHardcod-g356
Subject RecursionLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given two strings s and t (each length 0..1000), return the number of distinct subsequences of s that equal t. A subsequence is formed by deleting zero or more characters without changing the order of the remaining ones; two subsequences are distinct if they use different sets of index positions. The empty string is a subsequence of any string. Return an integer.

Implement
num_distinct(s: str, t: str) → int
Examples
in["rabbbit","rabbit"]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.