Summary
I recently interviewed for a Data Engineer position at MoEngage, which included a DSA round where I was asked to implement the 'Shuffle an Array' problem. Despite discussing several approaches for the solution, my candidacy was ultimately rejected.
Full Experience
I received a call from MoEngage HR regarding a Data Engineer opening. The interview process was described as having one DSA round, one System Design round, and one HR round. My first round was the DSA round. The interviewer provided a link to the LeetCode problem 'Shuffle an Array' and asked me to explain my approach and write code while discussing it. Initially, I proposed a brute-force idea of generating all permutations, but after discussing its time complexity, we agreed it wouldn't be an optimal solution. I then proceeded to explain multiple other approaches:
- Approach 1: Generate two random indices (using a random function) in the range [1, n], swap the elements at those indices, and then return the array.
- Approach 2: Iterate through the array. For each current index i, generate a random index j (typically within the range of elements not yet processed, e.g., [i, n-1]) and swap the elements at nums[i] and nums[j].
- Approach 3: Insert all elements into a HashSet (as in Java) and then randomly remove elements one by one to form the shuffled array. I did mention that this approach might not guarantee equal likelihood of all permutations.
Interview Questions (1)
The interviewer shared a link to the LeetCode problem 'Shuffle an Array'. The task was to design an algorithm to randomly shuffle an integer array, ensuring that all permutations of the array are equally likely. I needed to implement the Solution class with the following methods:
Solution(int[] nums): Initializes the object with the integer arraynums.int[] reset(): Resets the array to its original configuration and returns it.int[] shuffle(): Returns a random shuffling of the array.
Summary
I participated in a coding round for the Senior Software Engineer position at MoEngage, where I was tasked with solving a complex data processing problem involving log files to identify and count unique drivers for specific city visit triples.
Full Experience
During my Senior Software Engineer interview at MoEngage, the focus of the round was a challenging coding problem. I was given a scenario involving a large log file that tracked driver movements across various cities with timestamps. The core task was to extract 'triples' – sequences of three consecutive cities visited by a driver, ordered by timestamp – and then count the number of unique drivers associated with each distinct triple. This required careful parsing, grouping, sorting, and aggregation of data from the log file. The problem presented a good test of my data processing and algorithmic skills.
Interview Questions (1)
Suppose you have a big text log file and there are three columns:
NameCityTimestamp
Example log data:
Name City Timestamp
John city1 t4
Bob city1 t3
John city2 t1
John city3 t3
Bob city3 t2
John city4 t2
Bob city4 t1
The first column is a driver name, the second is a city name, and the final is a timestamp (32-bit integer).
This log file maintains a history of drivers.
We define a "triple" as a tuple of three consecutive cities a driver has been to that are ordered by timestamp.
Suppose t1 < t2 < t3 < t4, then we will have the following triples:
- for John, we have: (city2, city4, city3), (city4, city3, city1)
- for Bob, we have: (city4, city3, city1)
Write a program to output all the triples in the file and for each triple, output the count of unique drivers that have been to that triple.
For the example input, the output would be
(city2, city4, city3) 1
(city4, city3, city1) 2