Segmentify: Minimum Subsegments
Learn this problemProblem statement
Amazon Prime Video is developing a new feature called "Segmentify." This feature applies to a video with n (even) visual frames, where each frame is represented by a binary character in the array frames. In this format, a "0" represents a black pixel, and a "1" represents a white pixel.
Due to factors like lighting and camera angles, some frames may need horizontal or vertical flips (changing "0"s to "1"s and vice versa) to create consistent visuals. The objective is to divide the video into subsegments so that all frames in a subsegment are visually identical (i.e., the frames in a subsegment are either all "0"s or all "1"s). Additionally, each subsegment should have an even length.
The goal is to accomplish this segmentation with two criteria in mind:
- Minimize the number of flips required to form valid segments, let this be denoted by
B. - Among all configurations requiring
Bflips, minimize the total number of subsegments.
Given the binary string frames, determine the minimum number of even-length subsegments that can be created while utilising the least number of flips.
Note: A subsegment is a segment that can be derived from another segment by deleting some elements without changing the order of the remaining elements.
Function
getminSubsegments(frames: String) → intComplete the function getminSubsegments in the editor.
getminSubsegments has the following parameter:
string frames: the frames of the video
Returns
int: the minimum number of subsegments.
Examples
Example 1
frames = "1110011000"return = 2
Example 2
frames = "110011"return = 3Example 3
frames = "100110"return = 1Constraints
2 ≤ n ≤ 10^5, wherenis the length offramesand is even.- It is guaranteed that the string
framesonly consists of0s and1s.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026