You are given an integer array nums and an integer k. An integer x is almost missing from nums if x appears in exactly one subarray of size k within nums. Return the largest almost missing integer from nums. If no such integer exists, return -1. A subarray is a contiguous sequence of elements within an array.
Example 1
Input: nums = [3,9,2,1,7], k = 3
Output: 7
Explanation: 3 and 7 each appear in exactly one size-3 window; the larger is 7.
Example 2
Input: nums = [3,9,7,2,1,7], k = 4
Output: 3
Explanation: Only 3 appears in exactly one size-4 window.
Example 3
Input: nums = [0,0], k = 1
Output: -1
Explanation: With k=1 each element is its own window, and 0 appears in two of them, so no integer qualifies.
Slide a window of size k across nums. For every window, mark each distinct value as seen once more. A value that ends up seen in exactly one window is 'almost missing' — return the largest such value.
Run checks all cases above. Submit evaluates all test cases.