Problem · String
Secure Password
Learn this problemProblem statement
A password pwd is a binary string of even length. You may flip any character from 0 to 1 or from 1 to 0.
The password is secure when it can be partitioned into non-overlapping contiguous substrings such that:
- Every substring has positive even length.
- Every substring contains only
0characters or only1characters.
Return the minimum number of flips needed to make the password secure.
Function
securePassword(pwd: String) → intExamples
Example 1
pwd = "1110011000"return = 3Flip three characters so the first eight characters become equal, producing 1111111100. It can be partitioned into 11111111 and 00, so the minimum is 3.
Constraints
2 ≤ pwd.length ≤ 2 × 10^5pwd.lengthis even.pwdcontains only0and1.
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026