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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly