#K91607. Make Array Elements Equal
Make Array Elements Equal
Make Array Elements Equal
You are given an array of n integers. Your task is to determine whether it is possible to make all the elements equal by performing a sequence of allowed operations. After careful analysis, you will find that it is possible to achieve this if and only if the array is already in non-decreasing order. In other words, if the array is represented as \(a = [a_1, a_2, \dots, a_n]\), then the necessary and sufficient condition is that \(a_1 \le a_2 \le \dots \le a_n\).
For each test case, you should output YES
if the array satisfies the condition, or NO
otherwise.
inputFormat
The first line of the input contains a single integer T (1 \le T \le 104) representing the number of test cases. The description of the test cases follows.
For each test case:
- The first line contains an integer n (1 \le n \le 105) — the number of elements in the array.
- The second line contains n space-separated integers representing the elements of the array.
It is guaranteed that the total number of array elements over all test cases does not exceed 105.
outputFormat
For each test case, output a single line containing YES
if it is possible to make all the elements equal (i.e. if the array is in non-decreasing order), or NO
otherwise.
1
3
1 2 3
YES
</p>