Round 1: DSA
Questions:
- Understanding of the problem statement of the task.
- How was it solved?
- What was your role and what features did you work on?
- There was a heavy focus on testing. What was the code coverage of this project?
- What tools were used to identify the code coverage?
- How was the PR review process?
- How are security bugs handled?
- How will you sell your point of view if you come up with a new solution? (Expected answer: using performance benchmarking)
- How was the functional correctness of the project ensured when anyone raises a new PR?
DSA Problem:
- In a store, a colleague can work for multiple departments. Here are shifts of a colleague in various departments:
- In Bakery department: From 10 to 12
- In Checkout department: From 12 to 14
- In Dairy department: From 15 to 19
- Given the above split of shifts, provide an API/method to return the different shifts of a colleague for the day after merging contiguous shifts. This will be exposed to the colleague in different UI and help them plan their day accordingly.
- Sample Output: Shift timings in this case are 10 to 14 and 15 to 19.
Candidate's Approach
I proposed a simple merge interval solution that is used to solve the merge intervals problem on LeetCode. My solution was O(n log n) which involved sorting of the intervals. I quickly coded this.
Counter Question: To come up with a solution that took O(n) time.
- Hint: To use a boolean array.
- Solution: After a while, I got the hint and created a boolean array and marked the cells as true for whichever ones were part of the shift timings.
Here is the code for the solution:
public static void booleanMergeInterval(int [][] intervals){ boolean [] time = new boolean [25]; List<int []> result = new ArrayList<>(); for(int i = 0; i< intervals.length;i++){ int start = intervals[i][0]; int end = intervals[i][1]; while(start<end){ time[start]=true; start++; } } for(int i = 1; i< 25;i++){ int start = 0; int end = 0; if(time[i]==true){ start= i; while(time[i]==true){ i++; } end = i; result.add(new int []{start,end}); } } for(int [] inter : result){ System.out.println("Intervals are "+inter[0]+" ,"+inter[1]); } }
Interviewer's Feedback
No feedback provided.
Final Questions:
- Why Tesco?
Recommendations for Future Candidates:
- Interval problems - commonly seen in interviews.
- Merging sorted lists.
- K sorted lists.
- Sorting Linked Lists.
- Brush up on testing; I had read about Test Coverage for the code as well.