Domanda di colloquio di Zillow

Write a method to determine if a string2 is a substring of string1?

Risposte di colloquio

Anonimo

16 nov 2017

Seems like a good use for Fisher-Yates algorithm, cause it doesn't care for type of the object you'll store in your `deck` array. Here is the Pseudocode for Fisher Yates: for i from n−1 downto 1 do j ← random integer such that 0 ≤ j ≤ i exchange a[j] and a[i] Here is an implementation in JS: function shuffle(deck) { let temp; for (let i = deck.length - 1; i >= 0; i--) { index = Math.floor((Math.random() * 100) % deck.length); temp = deck[index] deck[index] = deck[i] deck[i] = temp } } Time complexity - O(n) Space complexity - O(1)

Anonimo

10 nov 2017

What data structures would you use to design a deck of cards and how would you randomly shuffle them?

1