Amazon Technical Flashcards

1
Q

Count Unique Characters of All Substrings of a Given String

A

Time O(N) | Space O(N)

Pattern:

  • Create a hash map. If the char is in HM, update its index, if not add -1.
  • Loop through HM
  • Set a positions to the hashMap’s index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Search Suggestions System

A

O(NN) Time | O(NN) space

Pattern:

  • Sort by lex order
  • Loop through searchWord
  • Loop through products in products,
  • if the index matches for searchWord and product and i < len(product), add it
  • Set the products arr to temp
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Flip String to Monotone Increasing

A

O(2 N) Time | O(N) Space

Pattern:

  • Calculate the best cost
  • Check if there are lower costs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Zombie in Matrix

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

Reverse Linked List

A

Time O (N), Space O(1)

Pattern

  • Keep next in temp
  • Set curr next to prev
  • Set prev to current
  • Set curr to next
  • return prev
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Linked List Cycle

A

Time: O(N) visit every node | Space: Adds every node

Pattern
- Uses memory address as hash

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

LRU Cache

A

Time O(1) | Space O(N)

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

Analyze User Website Visit Pattern

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

Reorder Data in Log Files

A

Time O(N log N) | Space O(N)

Notes:

  • you can split and check if it digit in one go
  • you can split in a lambda function, and specify array location
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Sum of Subarray Ranges

A

Time O(n^2) | Space O(1)

Notes
- Setting a left and right, while incrementing keeps track of the min and max

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

Count Binary Substrings

A

Time O(N) | Space O(1)

Notes
- Min of prev keeps track of lesser to ensure balance

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

Sum of Subarray Minimums

A

Time O(N^3) | Space O(N)

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

Minimum Swaps to Group All 1’s Together

A

Time O(data) | Space O(0s)

Pattern:

  • Determine the size of the sliding window by counting the number of 1s,
  • Min moves is the number of spaces that are not 1
  • Slide window, by iterating from the end of window
  • chance the window sum, if it encounters a 1
  • Find that window that has the least number of zeros to swap
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Minimum Swaps to Group All 1’s Together

A

Time O(data) | Space O(0s)

Pattern:

  • Determine the size of the sliding window by counting the number of 1s,
  • Min moves is the number of spaces that are not 1
  • Slide window, by iterating from the end of window
  • chance the window sum, if it encounters a 1
  • Find that window that has the least number of zeros to swap
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The kth Factor of n

A

O(N) Time | O(1) Space

Notes:
- Since we need kth factor, use a count to keep track

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

Number of Islands

A

Time O(Rows x Cols) | Space O(Rows x Cols)

Pattern

  • Loop through row and col, if there is a 1 call DFS on it
  • DFS is used to change all 1s into #
  • BC: if smaller than 0 or >= len or != 1 return
  • Make all 1s into #
  • Call DFS on all four directions
17
Q

Range Addition

A

Time O(Updates) | Space O(1)

Notes

  • Essentially you create a balance between the first IDX and IDX outside of the window
  • And in the second for loop you update all of the sums
18
Q

Merge Intervals

A

Time O (N) Time | O(N) Space

Pattern:

  • Sort based on lower bound
  • Start at next and keep result in arr
  • Compare max of currentEnd and nextEnd
  • add current case if mutate, else add both
19
Q

The Maze

A

Time O(N^2) | Space O(1)

  • Create a false map using double list comprehensions
  • Check marker if visted or == coordinates
  • Set up down left right
  • While loop the index to the end and see if it is possible
  • return True if it is
20
Q

Sell Diminishing-Valued Colored Balls

A

Not optimal

21
Q

Compare Version Numbers

A

Time O(2N length + max(Ns) | Space O (2N)

Pattern

  • split arr based upon ‘.’
  • loop through the largest version
  • get the char at location, if it is outside of the index add 0
  • int the char so it looses 0s