JPMorgan ChaseOA #24
Get Minimum Operations
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyBits & Math
One operation picks an element and changes it to floor(v/2); it may become 0. Find the minimum number of operations so that every pair of adjacent elements ends up with different parity; a pairwise greedy that only changes the right element does not work.
Input
The first line contains n, followed by n items; full original bounds 1≤n≤100000, 1≤items[i]≤2^30.
Output
Output a single integer answer.
Example 1
Input:
5
4 10 10 6 2
Output:
2
Example 2
Input:
5
6 5 9 7 3
Output:
3
Example 3
Input:
2
2 4
Output:
1
Example notes
The outputs of the three public examples are, in order: 2; 3; 1. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…