Make the array even
Practice
2.5 (20 votes)
Bit manipulation
Basic programming
Basics of bit manipulation
Problem
92% Success 4613 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array A of N integers. If you make the array whole using the following operation, then what is the minimum number of operations required to make the entire array even?
Note: It can be proved that this is always possible.
Operation
Select an index \(1 \leq i <N\) and perform operation:
P=Ai+Ai+1; Q=Ai-Ai+1;
Ai=P; Ai+1=Q;
Input format
- The first line contains an integer T denoting the number of the test cases.
- In each test case:
- The first line contains an integer N denoting the number of elements in the array.
- The second line contains N space-separated integers of array A.
Output format
For each test case print a single line denoting the minimum number of operations required to make the whole array even.
Constraints
- \(1 \leq T \leq 20000\)
- \(2 \leq N \leq 200000\)
- \(1 \leq A_i \leq 1e9 \forall i \in [1,N]\)
- Sum of N over all test cases will not exceed 200000
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
67 votes
Tags:
Basic ProgrammingBit Manipulation
Points:30
9 votes
Tags:
Bit ManipulationBasic ProgrammingBitmaskPrefixBasics of Bit Manipulation
Points:30
10 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of Bit ManipulationAlgorithms
Editorial
Login to unlock the editorial