#K10201. Product Sorting Validation
Product Sorting Validation
Product Sorting Validation
You are given a list of product IDs. Your task is to determine whether it is possible to arrange all the products in ascending order such that the sorted list exactly equals the sequence \(1, 2, \ldots, n\) where \(n\) is the number of products.
The condition means two things:
- The product list must not contain any duplicate IDs.
- After sorting, the product IDs must form a continuous sequence starting from 1 up to \(n\). In other words, if we denote the sorted list as sortedList, then it must satisfy \(sortedList = [1, 2, \ldots, n]\).
If these conditions are met, print YES
; otherwise, print NO
.
inputFormat
The first line of the input contains a single integer (n) denoting the number of products. The second line contains (n) space-separated integers representing the product IDs.
outputFormat
Output a single line: YES
if the products can be rearranged to form the continuous ascending sequence from 1 to (n), or NO
otherwise.## sample
4
4 2 1 3
YES