LeetCode Entry
3471. Find the Largest Almost Missing Integer
Max number in exactly 1 k-window
3471. Find the Largest Almost Missing Integer easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1455
Problem TLDR
Max number in exactly 1 k-window
Intuition
Brute-force lookup all numbers and all windows
Approach
- brainteaser O(n) solution possible
Complexity
-
Time complexity: \(O(n^3)\)
-
Space complexity: \(O(n)\)
Code
fun largestInteger(n: IntArray, k: Int) =
n.filter { n.toList().windowed(k).count { w -> it in w } < 2 }.maxOrNull() ?: -1
pub fn largest_integer(n: Vec<i32>, k: i32) -> i32 {
*n.iter().filter(|x|n.windows(k as _).filter(|w|w.contains(x)).count()<2).max().unwrap_or(&-1)
}
Comments