Distinct Occurrences Problem Statement
You are given two strings 'A' and 'B' of lengths 'N' and 'M' respectively. Your task is to determine how many distinct ways string 'B' occurs as a subsequence in string 'A'.
Input:
An integer 'T' representing the number of test cases.
Each test case contains:
- An integer 'N', representing the length of string 'A'.
- An integer 'M', representing the length of string 'B'.
- A string 'A'.
- A string 'B'.
Output:
For each test case, output a single integer indicating the number of distinct occurrences of 'B' in 'A' as a subsequence.
Example:
Input:
T = 1
N = 6, M = 2
'A' = 'aabbcc'
'B' = 'abc'
Output:
3
Explanation:
The subsequences of 'A' matching 'B' are 'abc' (from 1st 'a', 1st 'b', and 1st 'c'), 'abc' (from 1st 'a', 2nd 'b', and 2nd 'c'), and 'abc' (from 2nd 'a', 2nd 'b', and 2nd 'c'). Therefore, there are 3 distinct subsequences.
Constraints:
1 <= T <= 100
1 <= N, M <= 100
- Time limit: 1 second
Note:
A subsequence is a sequence derived from another sequence by deleting some elements without changing the order of the remaining elements.

AnswerBot
4mo
Count the number of distinct occurrences of one string as a subsequence in another string.
Iterate through string A and string B to find all occurrences of B as a subsequence in A.
Use dynamic programmi...read more
Help your peers!
Add answer anonymously...
Bounteous x Accolite Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q2. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q3. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more
>
Bounteous x Accolite Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

