Interleaving String
Updated
Problem statement
Given strings s1, s2, and s3, return whether s3 can be formed by interleaving s1 and s2.
An interleaving uses every character from both source strings exactly once while preserving the left-to-right order within each source. Characters chosen from the two sources may alternate in groups of any positive length.
Function
isInterleave(s1: String, s2: String, s3: String) → booleanExamples
Example 1
s1 = "aabcc"s2 = "dbbca"s3 = "aadbbcbcac"return = trueThe target can choose characters from both sources while retaining each source's internal order.
Example 2
s1 = "aabcc"s2 = "dbbca"s3 = "aadbbbaccc"return = falseNo sequence of source choices can produce the target without reversing or skipping a source character.
Example 3
s1 = ""s2 = ""s3 = ""return = trueThe empty target is the interleaving of two empty strings.
Constraints
0 <= s1.length, s2.length <= 100.0 <= s3.length <= 200.- All strings contain only lowercase English letters.
More Tokopedia interview questions
- Delete Node in a BSTPHONE SCREEN · Seen Jul 2021
- Rotate ImagePHONE SCREEN · Seen Jul 2021
- Validate Binary Search TreeONSITE INTERVIEW · Seen Aug 2021
- Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Jul 2021
- Online Stock SpanONSITE INTERVIEW · Seen Jul 2021
- Vertical Order Traversal of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
Similar questions at other companies
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Query Words Within K PositionsPalantir · PHONE SCREEN
- Edit DistanceDP World · PHONE SCREEN
- Longest Palindromic SubstringIBM · PHONE SCREEN
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Decode WaysThe D.E. Shaw Group · PHONE SCREEN
- Edit DistanceAstrotalk · PHONE SCREEN
- Longest Palindromic SubstringeBay · PHONE SCREEN
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEW
- Count Palindromic SubstringsThe Voleon Group · PHONE SCREEN