Problem · String
Check a Repeated String as a Subsequence
Learn this problemProblem statement
Given two nonempty strings str1 and str2 and a positive integer k, consider the string formed by concatenating str2 with itself exactly k times.
You may delete any characters from str1 without changing the relative order of the remaining characters.
Return true if the repeated string is a subsequence of str1. Otherwise, return false.
Function
isRepeatedSubsequence(str1: String, str2: String, k: int) → booleanExamples
Example 1
str1 = "abcabcabc"str2 = "abc"k = 2return = trueThe first six characters of str1 form abcabc, which is str2 repeated twice.
Example 2
str1 = "abacb"str2 = "abc"k = 2return = falseThe required repeated string has six characters, but str1 has only five characters, so it cannot be a subsequence.
Example 3
str1 = "axbyacbz"str2 = "ab"k = 2return = trueKeeping the characters at positions 0, 2, 4, and 6 produces abab.
Constraints
1 <= str1.length, str2.length <= 1000001 <= k <= 100000str1andstr2contain only lowercase English letters.