Microsoft Interview Question for SDE-2s

Country: India

Comment hidden because of low score. Click to expand.
of 0 vote

Part 1 - Overall design
The basic algorithm is that track session start and end times. You also have an 'interval generation class' which generates pairs of start and end times. Each pair represents a day. For example {2017-05-012T00:00:00, 2017-05-13T00:00:00} represents the day May 12 2017. Have a 'worker' class which can compute averages for a given collection of pairs/intervals. This 'worker' class would implement Java Callable interface and return the averages for the days it is assigned. Also have a 'controller' class which uses the 'interval generation' class to retrieve all intervals, creates a 'worker', assigns a batch of intervals to each worker then uses Java Executors and Futures to submit the 'worker' to the Java Executor. Once all 'worker's finish their assigned tasks, the 'controller' would have the result in the Futures returned by the workers.

Part 2- Calculation of skype call duration for a single day
This is the part done by the 'worker'. The work is assigned a batch of days.
For each day, the worker collects all calls which started or ended that day. For each such call, it adds the portion of time spent for that call on that day into a time counter. Then it increments the number of calls (call counter). Once done, the average for that day is the time counter divided by the call counter. It collects this average into a Map with the day interval as key and average as value. This is the Map which is returned as a Java Future

- jtogari223 January 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Very nice design approach. Just putting another perspective here ..

Two assumptions : Every call history is stored in DB table. Average call is to be calculated per user.

As the question says average has to be calculated per day, I assume a simple trigger/ation listener that gets invoked at 11:55PM everday, reads the db table (that stores call history along with start/end times) and returns the average call for that day for that user.

boundary cases - What if call is ended without hitting end button in which case trigger can skip to be called. Or for those false calls which are just made and disconnected. Lastly those calls for which (due to some system error/conflict/downtime) the call is not recorded in the DB. Lastly, if two calls are made from same user account from two different skype applications (from two different devices).

For these boundary scenarios, there can be a redundancy in the system to monitor on a 'per call' basis and keep recording the duration for every call and keep calculating the average-so-far and consolidate towards end of day.

Please let me know your opinion.

- rsumankumar January 23, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

Your assumption that average call duration is per user makes sense. If the total number of users is not too much, a single threaded / single process design is fine. Calculating the average once per day at 11:55PM is also makes sense, provided you are only asking for the average the next day and not during the same day. If the audience is a user who is looking at his own average call duration, the above assumptions make sense.
If the audience is an administrator who is looking into average call duration frequently and tracking averages for per user basis or per day basis you would need something more accurate (i.e., calculate frequently) and fast. Also, as the number of users increases (maybe into millions), we would need a multi-threaded design so that averages are calculated faster for a single day. To calculate today's averages, using the daily 'cron job' or trigger, it would have to make use of worker threads for a set of users. So each 'worker' instance I mentioned in my earlier post would be for a single day for a set of users. In order to make the averages available throughout the day and with somewhat more accuracy, the cron job would have to be done more frequently, say every three hours.

Boundary scenarios: I agree, the system could monitor on a per call basis and keep recording duration - I just assumed other parts of the system would do this or something similar (like tracking session to check for timeout) and then record the end time even if user failed to hit the end button. You could also skip calls whose end time was not recording so that inaccurate information is not used. Calls made from the same user account - I assumed other parts of the system would take care of this and create a unique session for each device.

- jtogari223 February 05, 2018 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

In the client program(That is the skype app mobile, skype app web) emit the simple metrics on start end time of the calls.
Then develop a client side metric aggregator library(javascript for browser, android for apps etc). This will just collect the metrics getting logged and throw it to a server. The server application could be exposing an api or simply listening to a queue(SQS if i may). So your client keeps sending this data onto this queue which is read by the server and saved in a data store.
Then you can build a layer on top of this data to interpret your result

- Yoda May 05, 2018 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More