GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 15 May 2022

[Solution] Equal After And CodeChef Solution | CodeChef Problem Solution 2022

You are given an array A=[A1,A2,,AN], consisting of N integers. In one move, you can take two adjacent numbers Ai and Ai+1, delete them, and then insert the number AiAi+1 at the deleted position. Here,  denotes bitwise AND. Note that after this operation, the length of the array decreases by one.

Formally, as long as |A|>1 (where |A| denotes the current length of A), you can pick an index 1i<|A| and transform A into [A1,A2,,Ai1,AiAi+1,Ai+2,,A|A|].

Solution Click Below:-  CLICK HERE

Find the minimum number of moves required to make all numbers in the resulting array equal.

Input Format

  • The first line of input contains an integer T — the number of test cases you need to solve.

  • The first line of each test case contains one integer N, the size of the array.
  • The second line of each test case contains N space-separated integers A1,,AN — the elements of the array A.
Solution Click:-  CLICK HERE

Output Format

For each test case, output on a new line the minimum number of moves required to make all numbers equal.

Constraints

  • 1T106
  • 2N106
  • Sum of N over all test cases is at most 106.
  • 0Ai<230

Subtasks

  • Subtask 1 (20 points):
    • 0Ai255
    • Sum of N over all test cases is at most 255.
  • Subtask 2 (30 points):
    • Sum of N over all test cases is at most 2000.
  • Subtask 3 (50 points):
    • Original constraints.
Solution Click:-  CLICK HERE

No comments:

Post a Comment