Problem: Count Even or Odd in Array

Tanmay and Rohit are best buddies. Tanmay gives Rohit a challenge involving an array of N natural numbers. The task is to perform and answer a series of queries on the array as follows:

Explanation:

Query Types:
  • Query 0: 0 x y - Update the element at index x to y in the array.
  • Query 1: 1 x y - Count the number of even numbers in the range from index x to y (inclusive).
  • Query 2: 2 x y - Count the number of odd numbers in the range from index x to y (inclusive).

Input:

The first line contains an integer 'N', the size of the array 'arr'.
Next line contains 'N' space-separated integers representing 'arr'.
The following line contains an integer 'q', the number of queries.
The next 'q' lines contain one of the specified queries (0 x y, 1 x y, or 2 x y).

Output:

For each query of type 1 and 2, output the result on a new line.

Example:

Input:
6
1 3 5 7 9 2
5
1 0 4
0 3 6
1 0 4
2 0 5
2 2 4
Output:
0
0
6
2

Constraints:

  • 1 ≤ N, Q ≤ 105
  • 0 ≤ x ≤ y ≤ N - 1
  • 0 ≤ arr[i] ≤ 109
  • 1 ≤ x ≤ N
  • 0 ≤ y ≤ 109
Note:
No need to print any output yourself, implement the function as specified.
Be the first one to answer
Add answer anonymously...
LTIMindtree Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter