#K36212. Taco Sorting Challenge

    ID: 25705 Type: Default 1000ms 256MiB

Taco Sorting Challenge

Taco Sorting Challenge

You are given one or more lists of integers. For each list, determine if it is possible to arrange it in strictly increasing order by repeatedly taking any element from the list and moving it to the front. Note that if the list contains any duplicate values, it is impossible to reorder it into a strictly increasing sequence.

Key Observation: Since moving an element to the front can help in positioning a smaller number before a larger one, any list with all distinct elements can always be transformed into a strictly increasing order. However, if duplicates exist, the requirement of strict ordering cannot be met.

For example, consider the following cases:

  • List: [3, 1, 2] → Output: YES
  • List: [5, 4, 3, 2, 1] → Output: YES
  • List: [2, 2, 2, 2] → Output: NO

inputFormat

The input is given via standard input (stdin). The first line contains an integer T that denotes the number of test cases. Each of the following T lines contains a space-separated list of integers representing one test case.

For instance:

4
3 1 2
5 4 3 2 1
2 2 2 2
1 9 2 8 3 7

outputFormat

For each test case, print a single line to standard output (stdout) with either YES if it is possible to reorder the list into a strictly increasing sequence using the allowed operation, or NO otherwise.

Example output for the above input:

YES
YES
NO
YES
## sample
4
3 1 2
5 4 3 2 1
2 2 2 2
1 9 2 8 3 7
YES

YES NO YES

</p>