Description
Solutions
Minimal Unique Segments
🤘 INTERN

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

Example 1:

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

Example 2:

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

Example 3:

Input:  userPassword = "zebra"
Output: 1
Explanation:
:)
Constraints:
    • 1 ≤ length of userPassword ≤ 10^5
    • All characters in userPassword are lowercase English letters.
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: