/*
* @lc app=leetcode.cn id=1608 lang=typescript
*
* [1608] 特殊数组的特征值
*/
// @lc code=start
function specialArray(nums: number[]): number {}
// @lc code=end
function specialArray(nums: number[]): number {
const n = nums.length
nums.sort((a, b) => a - b)
for (let i = 0; i < n; i++) {
const x = n - i
if (x <= nums[i]) {
if (!i || nums[i - 1] < x) return x
else break
}
}
return -1
}
test.each([
{ input: { nums: [3, 5] }, output: 2 },
{ input: { nums: [0, 0] }, output: -1 },
{ input: { nums: [0, 4, 3, 0, 4] }, output: 3 },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
expect(specialArray(nums)).toEqual(output)
})