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
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;
}