Find the Largest Almost Missing Integer

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
Inputnums = [3,9,2,1,7], k = 3
Output7
We return 7 since it is the largest integer that appears in exactly one subarray of size k.
Example 2
Inputnums = [3,9,7,2,1,7], k = 4
Output3
We return 3 since it is the largest and only integer that appears in exactly one subarray of size k.

Constraints

  • 1 <= nums.length <= 50
  • 0 <= nums[i] <= 50
  • 1 <= k <= nums.length

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate