Maximum Equal Parts for Prefixes
Updated
Problem statement
A team at Amazon is working to ensure all packages are correctly sorted for delivery. Each package has a label represented by an uppercase English letter. The full list of labels is given as the string packages, where the ith character is the label of the ith package.
To optimize the sorting process, the team wants to analyze each prefix of the string packages (from length 1 to n) and determine the maximum number of equal parts it can be divided into. Each part must satisfy the following conditions:
- Each part must have the same frequency of every character as every other part in that division
Given a string packages, calculate for each prefix t (from length 1 to n), the maximum number of equal parts into which the prefix can be divided, such that each part has the same number of occurrences of each character.
Function
maximumEqualParts(packages: String) → int[]Examples
Example 1
packages = "ABAB"return = [1, 1, 1, 2]Given, packages = "ABAB".
In the given example t represents prefix string and length represents the length of the prefix string.
Return [1, 1, 1, 2] as the answer.
Constraints
packagesconsists only of uppercase English letters ('A'to'Z').- The answer is computed for every prefix of
packagesof length1ton, wherenis the length ofpackages. - For each prefix, the maximum number of equal parts is at least
1, since a prefix can always be treated as a single undivided part.
More Amazon Online Assessment questions
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Count Suffix Word PairsTikTok · OATikTok interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Minimum Anagram PeriodVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 interview questions
- Cheating CodemakerJane Street · OAJane Street interview questions
- Minimum Anagram PeriodWells Fargo · OAWells Fargo interview questions