Amazon India | Online Assessment | 3.5 Years experience | April 2021
Anonymous User
729

Date: Somedate in April, 2021 (can't reveal the exact date :P )

Platform: Hackerrank

Structure of assessment:
There were 3 sections of the assessment:

  1. Coding challenge (2 questions based on Data Structures and Algorithms) and Coding approach (elaborate why you code the way you do) - 105 minutes
  2. Work style survey - 15 minutes
  3. Feedback survey - 5 minutes

Questions:

Question 1. Minimum Number of Swaps to Sort / Algorithm Swap
Given an array of distinct elements and a old sorting algorithm, you want to find the efficiency of that old sorted algorithm. What the old sorting algorithm does is -
=> It finds a pair of indices i and j such that j>i and arr[i]>arr[j] and j should be closest index to the right of i. Also, 0<=i,j<n, where n is number of elements in the input array.
=> After finding pair of indices, it swaps elements at those indices and continues to do this till the array becomes sorted.

We have to find the minimum number of swaps to sort the array using the above "old sorting algorithm".

Sample input: Let the given array be [5,4,1,2]
[5,4,1,2] -> pair (5,4) -> [4,5,1,2] -> pair (4,1) -> [1,5,4,2] -> pair(5,4) -> [1,4,5,2] -> pair(4,2) -> [1,2,5,4] -> pair(5,4) -> [1,2,4,5].

My attempt:
Was able to pass 8/13 test cases and for rest 5 I got TLE :(

Question 2. I forgot the question name, but it was having the exact same logic as finding the number of connected components : https://leetcode.com/problems/number-of-provinces/.

My attempt: Was able to pass all the test cases.

Result: Cleared the Online Assessment.

Comments (2)