Recently, I received a call from MoEngage HR regarding a Data Engineer opening. She mentioned that the interview process would include 1 DSA round, 1 System Design round, and 1 HR round.
She shared the meeting invite for the DSA round interview.
The interviewer asked the following question:
🔗 https://leetcode.com/problems/shuffle-an-array/description/
He shared the link and asked me to explain the approach and write code while discussing
First, I came up with a brute force idea: generate all permutations. After discussing the time complexity, we agreed that this solution wouldn’t work.
Then, I explained multiple approaches:
Approach 1: Generate two random indices (using a random function) in the range [1, n], swap them, and return the array.
Approach 2: Iterate through the array, and for each index i, generate a random index j and swap the two elements.
Approach 3: Insert all elements into a HashSet (in Java) and randomly remove elements, though this doesn’t guarantee ordering.
Despite discussing these, I was rejected. I’m not able to figure out what went wrong. Maybe the interviewer expected me to write the full solution. I’m not sure, and I’m feeling a bit low about it.