Check a Repeated String as a Subsequence
Updated
Problem 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.
More Quince interview questions
Similar questions at other companies
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Alternate String EndsCapital One · OACapital One interview questions
- Run-Length String CompressionSalesforce · OASalesforce interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
- Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
- Lost MessagesSuperhuman · OASuperhuman interview questions
- Reverse a StringFlexTrade · OAFlexTrade interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Reverse the Interior of Vowel-Bounded WordsVisa · OAVisa interview questions