Mphasis Hiring OA Question | Find All Anagrams in a String | Sliding Window | off campus 2024

Question · Posted Jun 2026

Problem Statement Given two strings s and p, return all starting indices of p's anagrams in s. An anagram is a word or phrase formed by rearranging the letters of another word, using all the original letters exactly once. The order of the output indices does not matter. Example 1 Input s = "cbaebabacd" p = "abc" Output [0, 6] Explanation The substring starting at index 0 is "cba", which is an anagram of "abc". The substring starting at index ...

The full answer & interview discussion are available to premium members.

Log in Create a free account