Question: time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a of n elements. You can

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a of n elements. You can apply the following operation to it any number of times:

Select some subarray from a of even size 2k that begins at position l (1ll+2k1n, k1) and for each i between 0 and k1 (inclusive), assign the value al+k+i to al+i. For example, if a=[2,1,3,4,5,3], then choose l=1 and k=2, applying this operation the array will become a=[3,4,3,4,5,3].

Find the minimum number of operations (possibly zero) needed to make all the elements of the array equal.

Input The input consists of multiple test cases. The first line contains a single integer t (1t2104) the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer n (1n2105) the length of the array.

The second line of each test case consists of n integers a1,a2,,an (1ain) the elements of the array a.

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output Print t lines, each line containing the answer to the corresponding test case the minimum number of operations needed to make equal all the elements of the array with the given operation.time limit per test1 second memory limit per test256 megabytes inputstandard input

input Copy 5 3 1 1 1 2 2 1 5 4 4 4 2 4 4 4 2 1 3 1 1 output Copy 0 1 1 2 0 Mata

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!