Round 1 – Online Assessment
Question: "Given an array of non-negative integers, arrange them to form the largest possible number."
Difficulty: Medium
Approach:
I first thought of sorting numbers in descending order but quickly realized 30 vs 3 would break this approach (330 < 303).
Switched to a custom comparator: compare a+b and b+a as strings.
Used functools.cmp_to_key in Python to implement the comparator.
Handled edge case where the result could have leading zeros.
My solution passed all hidden test cases.
Round 2 – Technical Interview
Discussion:
The interviewer asked me to explain my approach before coding.
We talked about why normal sorting fails.
He asked me about time complexity — I explained:
Sorting takes O(n log n) comparisons.
Each comparison takes O(k) time where k is max number of digits (since we compare concatenated strings).
So overall: O(n log n * k).
Then he asked for edge cases:
Array with single element.
Array with all zeros.
Array with numbers having same prefix (like [121, 12]).
I wrote a dry run for [3, 30, 34, 5, 9] step by step, explaining comparisons.