dsa2 min read
Find All Numbers Disappeared in Array — Index Negation O(n) O(1) [Meta Easy]
Find all integers in [1,n] missing from array of length n using O(n) time O(1) extra space via index negation.
Read →
1575 articles
Find all integers in [1,n] missing from array of length n using O(n) time O(1) extra space via index negation.
Find maximum consecutive ones if you can flip at most k zeros to one. Variable sliding window O(n) solution.
Return the third distinct maximum or the max if fewer than 3 distinct values exist. Three-variable tracking O(n) O(1) solution.
Design a class to find the kth largest element in a data stream. Min-heap of size k: the top is always the answer. Full C++, Java, JavaScript and Python.
Implement Fisher-Yates shuffle for uniform random permutation. Every arrangement is equally probable. O(n) time O(1) extra space.