Scramble String - Leetcode 87 - Python

Опубликовано: 12 Октябрь 2024
на канале: Lit Code
134
3

Leetcode Daily Challenge - March 30, 2023
Leetcode 87. Scramble String - Python Solution

Problem Statement
We can scramble a string s to get a string t using the following algorithm:

If the length of the string is 1, stop.
If the length of the string is greater than 1, do the following:
Split the string into two non-empty substrings at a random index, i.e., if the string is s, divide it to x and y where s = x + y.
Randomly decide to swap the two substrings or to keep them in the same order. i.e., after this step, s may become s = x + y or s = y + x.
Apply step 1 recursively on each of the two substrings x and y.
Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1, otherwise, return false.

===================================================

Key Moments
0:00 Intro to Scramble String
1:08 Explanation of Scramble String Solution
1:35 Code of Scramble String
5:50 Result for Scramble String

Support the channel by subscribing and hitting the like button.

Litcode Playlist: https://bit.ly/3uGBSHx

LinkedIn:   / sachin-singh-ss31  
Email: [email protected]

#leetcode #leetcodesolution #leetcodedailychallenge #codingpractice #learnpython #python #googleinterview #amazoninterviewpreparation