bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 567. Permutation in String

567. Permutation in String

Leetcode Solutions

Approach: Optimized Sliding Window

  1. Create two arrays of size 26 to store the frequency of each character in s1 and the current window in s2.
  2. Initialize a count to 0 to track the number of characters with matching frequencies in s1 and the window.
  3. Iterate over the first window in s2 (of size s1.length) and update the frequency array and count.
  4. Slide the window across s2 one character at a time, updating the frequency array and count for the entering and exiting characters.
  5. If at any point the count equals 26, return true.
  6. If the end of s2 is reached without the count reaching 26, return false.
UML Thumbnail

Approach: Using Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...