Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Given an array of N integers, you can do some operations on it

Given an array of N integers, you can do some operations on it

Computer Science

Given an array of N integers, you can do some operations on it. In each operation, you may choose two adjacent elements a[i] and a[i+1], and do either of the following two –

    1. Replace a[i] with a[i] + a[i+1] and delete a[i+1].

    2. Replace a[i+1] with a[i] + a[i+1] and delete a[i].

Note, performing any of these operations will reduce the array size by 1. Find the max array size, you can obtain, by doing these operations, such that, at last, all the elements of the final array are equal.

Print that maximum final size of the array.

Input Format –

The first line contains a single integer N, denoting the number of values in the array. Then, N lines follow, where each line contains a single integer, denoting the array values.

Output Format –

Print a single line, containing a single integer, the answer to the problem.

note
Constraints
1 <= N <= 2000

1 <= array values <= 1,00,000

view_list
Examples
Input:
4

1

2

2

1

Output:
2

Explanation:
We can finally obtain an array, of size 2, where each of the values of the array would be 3.

Option 1

Low Cost Option
Download this past answer in few clicks

1.3 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions