Segmentify: Minimum Subsegments
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:
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.
Complete 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.
Constraints
- 2 ≤ n ≤ 10^5, n is of even length
- It is guaranteed that string frames only consist of 0s and 1s.
A huge thanks to da best friend who so generouly helped with the Last Seen date update! 🐳
1Example 1
