To apply two pointer approach for sum problem, array need to be sorted, if not sorted use hash map.
Sub array sum are solved using HashTable(unordered_map), Some may solved by prefix sum.
Largest Element
In Bruteforce, compare each item with other(O(n 2 n^2 n 2 ))
In Better, sort it descending order, first item is the answer(O(n l o g n nlog n n l o g n ))
In Optimal, single pass through array(O(n))
Second Largest
Check Rotated Sorted
20 March, 2026: 00.07.12 ✔
Identify the graph and check first and last item of the list
Remove Duplicates
20 March, 2026: 00.03.18 ✔
Left Rotate By One Place
Left Rotate By D Place
20 March, 2026: 00.02.58 ❌
Failed at optimization
Bruite Force Trade-Off: Space O(N) vs Time O(N^2)
Optimal: Reverse 3 times(partion wise)
Moves Zeros to end
20 March, 2026: 00.02.54 ✔
Linear Search
Find Union
20 March, 2026: 00.07.26 ❌
Failed at optimization
Handle the duplicate value issue
Find Missing numbers
Brute force: find an element from an array with 2 loop, one is for iteration, other is to find that iterated item.
Bit Approach: xor of [0, n](xr^=i) vs xor of item of array
Math Approach: sum of [0, n](n*(n+1/2)) vs sum of item of array
Maximum Consecutive Ones
Find the number that appear once
Sub Array Sum(K) - Positive
09 April, 2026: 00.19.01 ❌
Failed at optimization
Bruteforce: O ( n 2 ) O(n^2) O ( n 2 ) , Prefix Sum: O ( n 2 ) O(n^2) O ( n 2 ) , Hash Table: O ( n ) O(n) O ( n ) , Sliding Window: O ( n ) O(n) O ( n )
Subbary can be formed in multiple element, so don't just check and perform incerement, decrement, store the previous value then check and perform incerement, decrement
Length of Sub Array Sum(K)
09 April, 2026: 00.26.20 ❌
Failed at implmentation
Handle the case where forward element doesn't make any effect like 0 0 0 or -2 2 4 -4
Sliding window fail for negative number, because during shrinking it perform some unpredictable behavour(- - = +)
Length of largest sub array with 0 sum
09 April, 2026: 00.01.20 ✔