Coding round (screen shared)
You are given a function that, for a particular user, returns a list transactions for the shares they bought or sold in the format "<date>,<BUY|SELL>,<company>". You are given another function that returns a list of friends of a particular user.
Now, for a particular user, you need to print the friend alerts in the following format: "<net_trades>,<BUY|SELL>,<company>" i.e. total number of shares bought or sold by his friends for every company.
e.g. if the transactions of his friends are
"2018-01-01,BUY,Company-1"
"2018-01-02,SELL,Company-1"
"2018-01-03,BUY,Company-1"
"2018-01-04,SELL,Company-2"
then the output should be
"1,BUY,Company-1" -> 2 buy 1 sell = 1 buy
"1,SELL,Company-2"
Note that the ordering should be on the basis of net_trades (irrespective of buy/sell info). Also, if the net_trades is same, then the ordering must be on the basis of company name.
Think of the best data structure to be used. Moreover, how can you optimize if you are told to do the same thing for every user (1000 of them).