Permutation in String You have been given two strings ‘str1’ and ‘str2’ of length N and M respectively. Your task is to check whether string ‘str2’ contains one of the permutations of string ‘str1’ as its substring. In other words, find whether there exists any permutation of string ‘str1’ that is a substring of ‘str2’...

read more
CodingNinjas
author
2y
1. Firstly, I gave the brute force approach in which I one by one checked every character of string 1 in string 22. I then optimised it using the unordered map to store frequency of each character....
see more
CodingNinjas
author
2y
Naive ApproachWe naively generate all the permutations of string ‘str1’ and then check for each permutation if it is present as a substring of the string ‘str2’ or not.Space Complexity: O(n^2)Explanat...
see more
CodingNinjas
author
2y
SortingIn this approach, instead of comparing each permutation of ‘str1’ to M-N substrings of ‘str2’ we will sort each substring of ‘str2’ of size N and compare it with sorted ‘str1’. The idea be...
see more
Add answer anonymously...
Amazon Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2023 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter