Problem Brief
Find Minimum Number of Transitions
OA
See Tiktok online assessment and hiring insights
Find the minimum number of changes to make the array consisting of binary numbers with the least number of transitions from 0 -> 1 or 1 -> 0.
Function Description
Complete the function minTransitions in the editor.
minTransitions has the following parameter:
int[] arr: an array of binary integers
Returns
int: the minimum number of transitions
1Example 1
Input
arr = [1, 0, 1, 0, 1]
Output
1
Explanation
The array can be transformed to
[0, 0, 1, 1, 1] after swapping the index 0 and 3, resulting in only one transition from 0 to 1. Alternatively, it can also be transformed to [1, 1, 1, 0, 0] with one transition from 1 to 0. Therefore, the minimum number of transitions is 1.Constraints
Limits and guarantees your solution can rely on.
đ¶