3705. Find the Largest Almost Missing Integer
My accepted Python solution to LeetCode problem 3705, Find the Largest Almost Missing Integer, running in 7ms.
- Difficulty: Easy
- Python
- Runtime 7ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.2MB, accepted 2025-12-31.
class Solution:
def largestInteger(self, nums: List[int], k: int) -> int:
from collections import Counter
n = len(nums)
# Count how many subarrays of size k each element appears in
count = Counter()
for i in range(n - k + 1):
for num in set(nums[i:i+k]): # use set to count each element once per subarray
count[num] += 1
# Find the largest that appears exactly once
result = -1
for num, c in count.items():
if c == 1 and num > result:
result = num
return result