13. Arrays (medium)
buy & sell stocks✅ Next permutation🔥 Longest consecutive seq🔥 Rotate matrix by 90 CW✅ Count subarrays with sum k🔥 Rearrange the array in alternating + & - items ✅ Set matrix rows & cols to 0s for zero elmt✅ Spiral matrix✅ Leaders in an array✅ ---------------------------------------------------------------------------------------------------------- 1. Two sum problem- return index of 2 elements in array which adds up to the target sum Brute - time: O(N^2), space:O(1) linear search with two loops ------------------------------------------------------- Better: time: O(NlogN), space: O(N) mapping with two pass ( first build the map & next do a linear search and find remaining sum in map ) ------------------------------------------------------- Optimal - time: O(n), space: O(n) mapping with single pass (first check if answer exists & if not then insert the pair in map) Also, we prefer unordered...