Amazon Online Assessment October 2021

So after seeing dozens of OA posts on LeetCode in preparation for my own, I am here to give back to the community by sharing my own experience.
Duration - 70 mins
Platform - HackerRank
Role - SDE Intern EMEA

  1. Exactly this - https://leetcode.com/problems/the-kth-factor-of-n/
  2. Given an array of N numbers and a number K, find the minimum number of groups that the array can be split into. Rule: max-min of any group should not exceed K

My solution for question 2:

int func(vector<int>& arr, int K) {
	sort(arr.begin(), arr.end());
	int idx = 0, answer = 1;
	for(int i = 0; i < arr.size(); i++) {
		if(arr[i] - arr[idx] > K) {
			answer++;
			idx = i;
		}
	}
	
	return answer;
}
Comments (6)