FastPrepPermutation in String
Problems/Permutation in String

Permutation in String

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. The task as reported is to decide whether some rearrangement of one string occurs inside another. The review also had four more coding questions. The process was an online assessment and then a remote interview day, and the review does not say at which step this one came up.

The review gives no limits and does not say whether the rearranged letters must sit next to each other. Here the permutation must occupy consecutive characters of s2, both strings are lowercase with up to 10^4 letters, and you return true or false.

Our version is about 90% the same as the reported question.

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

In other words, is there a run of s1.length consecutive characters in s2 that uses exactly the same letters as s1, each the same number of times?

Function

checkInclusion(s1: String, s2: String) → boolean

Examples

Example 1

s1 = "ab"s2 = "eidbaooo"return = true

The window ba (indices 3 and 4 of s2, 0-based) uses the same letters as ab, so a permutation of s1 appears and the answer is true.

Example 2

s1 = "ab"s2 = "eidboaoo"return = false

s2 contains a b and an a, but they are never next to each other, so no window of length 2 matches.

Example 3

s1 = "abc"s2 = "ab"return = false

s1 is longer than s2, so no window fits and the answer is false.

Constraints

  • 1 <= s1.length, s2.length <= 10^4
  • s1 and s2 consist of lowercase English letters.

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Longest Substring Without Repeating CharactersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Longest Substring Without Repeating CharactersAmazon · ONSITE INTERVIEW
  • Longest Substring Without Repeating CharactersInfosys · ONSITE INTERVIEWInfosys interview questions
  • Longest Substring Without Repeating CharactersOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Longest Substring with At Most K Distinct CharactersGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Substring Without Repeating CharactersBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Sliding-Window Rate LimiterStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Longest Substring Without Repeated CharactersDatadog · ONSITE INTERVIEWDatadog interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean checkInclusion(String s1, String s2) {
        // Write your code here.
    }
}
Checking account…