Code Room
CodingHardcod-g028
Subject Dynamic programming 2dLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given two strings s and t, count the number of distinct subsequences of s that exactly equal t. A subsequence is formed by deleting zero or more characters without reordering; different sets of deleted positions count as different subsequences even if the resulting string is identical. Return the count; it is guaranteed to fit in a 64-bit signed integer. Both strings contain only English letters and have length up to 1000.

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.