FastPrepFind P-Matching Score
Problems/Find P-Matching Score

Find P-Matching Score

Amazon logoAmazon● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Amazon has an extensive customer database. To prevent customers from having very similar usernames, Amazon's Customer Database Management Team has decided to define a "p-matching" score between two usernames.

Consider two users with their respective User IDs as userID1 of length n and userID2 of length m. Each User ID is represented as a string of lowercase English letters. The p-matching score of userID1 with respect to userID2 is the maximum number of distinct indices i such that the string formed by concatenating characters userID1[i], userID1[i + p]... userID1[i + (m - 1) x p] can be rearranged to userID2 where 0 ≤ i and i + (m - 1) * p < n.

Given two strings representing user IDs, find the p-matching between the given user IDs.

Function

findScore(userID1: String, userID2: String, p: int) → int

Complete the function findScore in the editor.

findScore has the following parameters:

  1. String userID1: the username of 1st user
  2. String userID2: the username of 2nd user
  3. int p: the interval at which the characters from userID1 are concatenated

Returns int: the p-matching score of userID1 with respect to userID2.

Examples

Example 1

userID1 = "acaccaa"userID2 = "aac"p = 2return = 2

• Starting at index i = 0, increment i by p = 2, the string formed by concatenating characters userID1[0], userID1[2], userID1[4] is newString = "aac". It equals userID2 so i = 0 is a valid starting index.

• Starting at index i = 1, concatenate userID1[1], userID1[3], userID1[5] into newString = "cca". No rearrangement of this string will make it equal to string userID2 so i = 1 is not a valid starting index.

• Starting at index i = 2, concatenate userID1[2], userID1[4], userID1[6] into newString = "aca". It can be rearranged to "aac" so i = 2 is a valid starting index.

There are 2 valid starting indices, so the p-matching score is 2.

Constraints

  • 1 ≤ userID2.length ≤ userID1.length ≤ 10^5
  • 1 ≤ p ≤ 10^5
  • userID1 and userID2 contain only lowercase English letters.

More Amazon interview questions

  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
  • Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
  • Perfect SubstringAXQ Capital · OA
  • Longest Distinct StringSuperhuman · OASuperhuman interview questions
  • Longest Substring Without Repeating CharactersAkuna Capital · OAAkuna Capital interview questions
  • Perfect SubstringsVisa · OAVisa interview questions
  • Vowel SubstringSnowflake · OASnowflake interview questions
  • Count Distinct Fixed-Length SubstringsAdobe · OAAdobe interview questions
  • Video ID Generation (Generic)TikTok · OATikTok interview questions
  • Unaligned DedupeRubrik · OARubrik interview questions
  • Get Max OccurrencesIBM · OAIBM interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int findScore(String userID1, String userID2, int p) {
      // write your code here
    }

}
Checking account…