I recently had amazon telephonic round. The interview started with my introduction. Then straight, we started to problem solving.
Given a large file containing address of people in India, the values are comma separated. We need to find the state. The data can be in any order and people might have typed pin code anywhere, either after city name or after state name or even after country name. I gave him a approach of maintaining a list of state names and then splitting the given data and iterating over the complete data. If we match the state, we can just print.
Given a large data of stocks containing stock code, action, number of stocks, Transaction Rate(price), and transaction rate. Find percentage profit or loss for the given date. First, I told him that I will create a map of string and map of transaction rate and number of stocks. Then he said this will not work, and then I changed my map to map of string and stack of pairs. Still not able to come up with a data structure which will solve the problem.
StockCode Action Number of Stocks TransactionRate TransactionDate
INFY BUY 5 10 1/1/2010
INFY SELL 2 5 1/5/2010
INFY BUY 10 20 1/1/2015
INFY SELL 13 14 1/1/2020
INFY GIVE 6 1/1/2021 Prepared a lot, trees, graph, dp but I just shit in my interview. He said HR will give the feedback, but the moment he asked the 2nd question, I know I am not selected for further rounds. Missed such a great opportunity :(