Amazon | OA1 New Grad 2022 | Minimum Number of Groups

I don't remember the exact wordings but. Given an array of integers, and a maximum difference k, return the minimum number of groups that any two integers do not have difference bigger than k.

Say, we have [6,1,3,4,3,5], and k is 2, we will return 2 because we have minimum of two groups [1,3,3] and [4,5,6].

The way I solved it is that I sorted the array first and iterate through the array. Is there a more optimal solution for this one?

Comments (7)