Company: Coinbase
Difficulty: medium
Restaurant Chain A restaurant chain has N restaurants. Each restaurant is given a unique ID from 0 to N-1. To establish connectivity among all the restaurants, the head office maintains a hierarchy with N connections. The restaurant with head office is given an ID 0. A restaurant is further connected to a maximum of two restaurants. For every restaurant A, a new restaurant is always added to the left of it and its left connection is occupied then a restaurant A is added to the right of it. The system maintains the count of permanent customers of every restaurant. An annual festival is being organised in one of the restaurants. To select which restaurant will host the festival, an algorithm is used which generates a number M and makes a sequence of restaurant IDs from traversing the hierarchy so that for every restaurant, the given rule is followed. The rule is: for a restaurant with ID X, first the left connected restaurant to X is added, then the given restaurant with ID X is added an