American Express On-site | SDE 1 | New grad
Anonymous User
3002

Q1. A man wants to travel across a map with 'n' cities labelled from 0 to 'n-1'.There are (n-1) roads which connect the cities in such a way that each pair of distinct cities is connected either by a direct road or along a path consisting of direct roads. There is exactly one way to reach any city from any other city. Given he has 'm' dollars and at every city has to pay some amount (cost of entering each city given as dictionary), find the maximum number of cities he can visit. He cannot visit any city more than once and will always start from city 0.
Follow up: He can only visit one even numbered city apart from 0.

Q2. Given a 2D matrix of integers with a source and destination, find the path with the maximum sum given that there can be only ONE turn in the path. Diagonal moves not allowed.

Q3.'n' prisoners are standing on a circle, sequentially numbered from to 0 to n-1. An executioner walks along the circle, starting from prisoner 0, removing every k-th prisoner and killing him. As the process goes on, the circle becomes smaller and smaller, until only one prisoner remains, who is then freed. Find out which prisoner will be the final survivor.
For example, if there are n=5 prisoners and k=2, the order the prisoners are killed in will be 1, 3, 0, and 4, and the survivor will be 2.

(I don't remember the examples for other questions.)

Comments (5)