String Subsequences π³
Learn this problemProblem statement
Given two strings, determine the number of times the first one appears as a subsequence in the second one. A subsequence is created by eliminating any number of characters from a string (possibly 0) without changing the order of the characters retained.
Function
getSubsequenceCount(s1: String, s2: String) β long
Complete the function getSubsequenceCount in the editor below.
getSubsequenceCount has the following parameters:
string s1: the first string, which always has a length of 3string s2: the second stringReturns
int: the number of times s1 appears as a subsequence in s2
Examples
Example 1
s1 = "HRW"s2 = "HERHRWS"return = 3HRW appears at 1-based positions (1, 3, 6), (1, 5, 6), and (4, 5, 6), so the count is 3.
Example 2
s1 = "ELO"s2 = "HELLOWORLD"return = 4ELO appears at 1-based positions (2, 3, 5), (2, 3, 7), (2, 4, 5), and (2, 4, 7), so the count is 4.
Example 3
s1 = "ABC"s2 = "ABCBABC"return = 5ABC appears at 1-based positions (1, 2, 3), (1, 2, 7), (1, 4, 7), (1, 6, 7), and (5, 6, 7), so the count is 5.
Constraints
length of s1 = 31 β€ length of s2 β€ 5*105s1 and s2 consist of uppercase English letters, A-Z.