Question 2:
You are given a map where key is city and value is population. Write a method that returns a random city but randomness is weighted by population of city. Ex: if NYC is 8M and Dallas is 4M, then method should return NYC twice as much as Dallas.
类似 https://leetcode.com/problems/random-pick-with-weight/
45min phone interview. Started with 5-10 min introduction and around 30-35min to code, followed by 3-5min for questions.
Question 1) Write a function that returns whether a list of strings is sorted given a specific alphabet.
words = [“cc”, “cb”, “bc”, “ac”]
alphabet = [‘c’, ‘b’, ‘a’]
Output: true
Similar to : https://leetcode.com/problems/verifying-an-alien-dictionary/
Follow up: How would you make this production ready code and how would you verify/test it i.e., since it is not possible to write all possible test cases, how would you go about it?
Question 2) Given a reasonably well balanced binary tree, implement an iterator that iterates over it in in-order fashion.
Note: Parent pointer does not exists
Asked Time and Space complexities for each of them.