FastPrepFastPrep
Problem Brief

Minimal Unique Segments

INTERNOA

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 Description

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 :)

1Example 1

Input
userPassword = "aabcdea"
Output
3
Explanation
Example 1 illustration
The password can be partitioned into a minimum of 3 valid segments. Return 3.

2Example 2

Input
userPassword = "alabama"
Output
4
Explanation
The minimum partitions are "al", "ab", "a", "ma".

3Example 3

Input
userPassword = "zebra"
Output
1
Explanation
:)

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ length of userPassword ≤ 10^5
  • All characters in userPassword are lowercase English letters.
public int minimalUniqueSegments(String userPassword) {
  // write your code here
}
Input

userPassword

"aabcdea"

Output

3

Sign in to submit your solution.