Google | L4 | Seattle | Jan 2020
Anonymous User
1725

Five rounds each of 45 minutes. All coding questions, no behavioral.

Round 1

Question

You are given an deck of cards, each labelled anywhere from 1 to 52.
A straight is defined as a set of five cards with consecutive labels, eg: 4, 5, 6, 7, 8
Given n cards, write a function that returns true if those cards can be arranged to contain all straights

Example

func ("2, 5, 6, 7, 10, 3, 4, 8, 9, 1") returns true.
func ("2, 5, 6, 7, 10, 3, 4, 8, 9") returns false.

Follow up

The cards can be labelled as any integer.

Round 2

Question

You are given a vector of operations. Each operation is of three parts: { [a-z], [<>], [a-z] }
[a-z] => single lowercase alphabet.
[<>] => 'greater than', or 'less than' operation.
Write a function that returns true if the operations are valid.

Example

func ({{"a", ">", "b"}, {"b", ">", "c"}}) return true
func ({{"a", ">", "b"}, {"b", ">", "a"}}) return false

Follow up

The input could also have integers, eg. ({{"a", ">", "1"}, {"b", ">", "2"}})

Round 3

Question 1

Given the root node of a binary tree and a node in the binary tree, delete that node from the binary tree and return the modifed root node.

Follow up

I worte a recursive solution. Interviewer asked me to write an iterative solution.

Question 2

We have a system with these properties:

  • System does a set of push and pop operations on a stack of integers.
  • Push and pop operations are interleaved.
  • A pop operation is never done on empty stack.
  • Each push operation increments an iteration variableI(integer) and pushes it into the stack.
  • The system stops push operations once the iteration variable reaches N (a variable in the question).
  • The iteration variable starts from Zero.
  • The system stops pop operations, once stack is empty.
  • After each pop, the system writes out the popped element.

Given a string, write a function that returns true, if for some N, that string can be outputted by a run of this system.

Example

func({0, 3, 2, 1}) returns true. A set of valid operation with N = 3 is:

  1. push (will push 0 and increment iteration to 1, stack is [0])
  2. pop (will print 0, stack is [])
  3. push (will push 1 and increment iteration to 2, stack is [1])
  4. push (will push 2 and increment iteration to 3, stack is [2, 1])
  5. push (will push 3 and increment iteration to 4, stack is [3, 2, 1])
  6. pop (will print 3, stack is [2, 1])
  7. pop (will print 2, stack is [1])
  8. pop (will print 1, stack is [])

func({0, 3, 1, 2}) returns false. To print "0, 3", steps #1 to #5 from the previous section will needed. After that there is no way to print 1 without printing 2. (since print happens on pop and 1 is after 2 in the stack)

Follow up

I wrote an O(n) time, O(n) space solution.
Interviewer asked for an O(1) space solution.

Round 4:

Round 5:

Comments (5)