Given two strings, find out how many times the first string appears as a subsequence within the second string. A subsequence is formed by removing any number of characters (including zero) from a string without altering the order of the remaining characters.
Given two strings, find out how many times the first string appears as a subsequence within the second string.
s1 = "ABC" s2 = "ABCBA"
The string s1 appears 5 times as a subsequence in s2 at 1-indexed positions of {1, 2, 3}, {1, 2, 7}, {1, 4, 7}, {1, 5, 6, 7}, and {5, 6, 7}. The answer is 5.
s1 = "HRW" s2 = "HERHRWS"
The string s1 appears 3 times as a subsequence in s2.
s1 = "ELO" s2 = "HELLO WORLD"
The string s1 appears 4 times as a subsequence in s2.
Two strings s1 and s2.
The number of times s1 appears as a subsequence in s2.
Hard