Date: Somedate in April, 2021 (can't reveal the exact date :P )
Platform: Hackerrank
Structure of assessment:
There were 3 sections of the assessment:
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.