SDE-1 (New Grad)
1 min read
Total Rounds: 4
- [Medium] leetcode.com/problems/least-number-of-uniqu..
- [Easy] Basic Sorting on the basis of Parameters.
Find the second largest number from an array of numbers represented as strings. For Ex- input = ["21", "32", "432", "435", "9982", "324", "1", "98", "435"] Output = "435" Constraints = A number can have 2^10 (1024) digits.
Let us store the elements in a hashmap of
[length of string, a max-heap containing the elements of the same length]. Grab the largest length as start popping out elements until I found the second largest one. Mentioned the edge cases that may arise here.
i. There might be multiple instances of numbers of the highest length. ii. Input consisting of just 1 or no element.
Time Complexity: O(n)
Got panicked and couldn't write the working code. The interviewer was running out of time and told me if I could complete it. I finally told him I can write the brute force sort solution for this. Wrote the brute force code.
- Told the interviewer about Kadane's Algorithm and implemented it.