GUPTA MECHANICAL

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

Wednesday 8 June 2022

[Solution] Minimum number of Flips CodeChef Solution | CodeChef Problem Solution 2022

Chef has an array A of length N consisting of 1 and 1 only.

In one operation, Chef can choose any index i (1iN) and multiply the element Ai by 1.

Find the minimum number of operations required to make the sum of the array equal to 0. Output -1 if the sum of the array cannot be made 0.

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.
Solution Click Below:-  CLICK HERE


  • First line of each test case consists of a single integer N denoting the length of the array.
  • Second line of each test case contains N space-separated integers A1,A2,,AN denoting the array A.

Output Format

For each test case, output the minimum number of operations to make the sum of the









 array equal to 0. Output -1 if it is not possible to make the sum equal to 0.

Constraints

  • 1T100
  • 2N1000

No comments:

Post a Comment