Arrays Flashcards
1
Q
Two Number Sum
A
O(nlog(n) time | O(1) Space
Use two pointers starting at opposite ends of a sorted array. Move inward in steps until pointers are equal or a matching pair is found.
2
Q
Validate Subsequence
A
O(n) time | O(1) space
Use a pointer starting at index 0 of sequence. Iterate over array and compare against value at pointer. If value is next in sequence increment pointer. If all values are found in sequence return true
3
Q
Sorted Squared Array
A
O(n) time | O(n) space
Use 2 pointers at opposite ends of array. Get absolute value of values under pointers. Prepend the larger value and move pointer inward. Loop n number of times where n is length of input array.