Minimal Unique Segments
Learn this problemProblem statement
Your team at AMZ is currently working on an innovative algorithm to generate password suggestions when users create a brand-new account.
Imagine a string composed solely of lowercase English letters that qualifies as "redundancy-free" — meaning that each individual character appears at most once within that string. To ensure minimal repetition, the developers want to suggest a password that can be split into the smallest number of these redundancy-free segments.
In this challenge, you are provided with an input string called userPassword. Your task is to determine the minimum number of segments into which userPassword can be partitioned so that every segment is redundancy-free.
Function
minimalUniqueSegments(userPassword: String) → int
Complete the function getNumberRedundancyFree in the editor.
getNumberRedundancyFree has the following parameter:
string userPassword: the given password
Returns
int: The minimum number of segments required to divide the string into redundancy-free parts :)
Examples
Example 1
userPassword = "aabcdea"return = 3
Example 2
userPassword = "alabama"return = 4Example 3
userPassword = "zebra"return = 1Constraints
1 ≤ length of userPassword ≤ 10^5- All characters in
userPasswordare lowercase English letters.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026