Non-Alternating Binary Partitions
Updated
Problem statement
You are given a binary string s and an integer frame. Split s into the minimum number of non-overlapping contiguous substrings so that every substring satisfies both rules:
- Its length is at most
frame. - It is not perfectly alternating.
A perfectly alternating substring changes bit at every adjacent position, such as 01, 10, or 1010. A single-character substring is allowed.
Function
minNonAlternatingPartitions(s: String, frame: int) → intExamples
Example 1
s = "101101"frame = 4return = 3One optimal split is 1011 | 0 | 1. The first part has length 4 and is not perfectly alternating, and single-character pieces are allowed, giving 3 substrings.
More The D.E. Shaw Group Online Assessment questions
- Count Lucky TicketsOA · Seen Nov 2026
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Minimum Frames for Equal ChunksOA · Seen Jul 2026
- Tree PointsOA · Seen Jan 2025
- Get Minimum CostOA · Seen Jan 2025
- Subarray RemovalOA · Seen Oct 2024
- Count the Number of Incremovable Subarrays IIOA · Seen Sep 2024
- Subarray RemovalOA · Seen Aug 2024
- Get Minimum CostOA · Seen Jun 2024
- Find Number of Interesting PairsOA · Seen May 2024
Similar questions at other companies
- Longest Palindromic SubsequenceAXQ Capital · OA
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA