Harry And The Magical Pile
Practice
5 (1 votes)
Sorting
C++
Math
Algorithms
Basic math
Problem
78% Success 207 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Harry is a brilliant student in the class and hence his teacher assigned him a problem. He has been given \(N\) piles of stones denoted by an array \(A\) where \(A[i]\) represents the number of stones in each of the \(i^{th}\) piles. All piles are arranged in sequence.

Harry has been asked to make this whole combination magical by performing the below operations some number of times.

  • Choose any two adjacent piles and merge them after merging the new pile formed will have the sum of stones in the two piles before merging.

A combination is magical if the sequence formed by their count of stones is a palindrome. Your task is to help Harry, find the minimum number of operations needed to make the whole combination magical.

Input Format:

  • The first line contains a single integer \(T\) denoting the number of test cases.
  • The first line of each test case contains an integer \(N\), denoting the number of elements in the array \(A\)
  • The second line of each test case contains \(N\) space-separated integers, denoting the elements of array \(A\).

Output Format:

For each test case, print the minimum number of operations needed to make the whole combination magical.

Constraints:

\(1 ≤ T ≤ 10\)

\(1 ≤ N ≤ 10^5\)

\(0 ≤ A[i] ≤ 10^9\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
836 votes
Tags:
Ad-HocSimulationEasyMathematicsOpenApprovedMathamatics
Points:20
9 votes
Tags:
OpenAlgorithmsApprovedEasyMathamatics
Points:20
1 votes
Tags:
Easy