Amazon India

Amazon India

SDE-1 (New Grad)

Total Rounds: 4


  1. [Medium]
  2. [Easy] Basic Sorting on the basis of Parameters.


  1. 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.


Approach Taken

  1. Let us store the elements in a hashmap of [key, values] as [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.

  2. Told the interviewer about Kadane's Algorithm and implemented it.