Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

35. Permutation in String

MediumDay 11 of 60Sliding Window

Given two strings s1 and s2, return true if some rearrangement (permutation) of s1 appears as a contiguous substring of s2, and false otherwise.

Example 1
Input: s1 = "ab", s2 = "eidbaooo"
Output: true
s2 contains "ba", which is a permutation of "ab".
Example 2
Input: s1 = "ab", s2 = "eidboaoo"
Output: false
Constraints
  • 1 <= s1.length, s2.length <= 10^4
  • Both strings contain only lowercase English letters
Hints
Frequently asked at: Microsoft, Amazon, Meta, Oracle
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min