Max Min Discussions | Algorithms | HackerRank
  • + 0 comments

    Two pointer approach

    def maxMin(k, arr):
        # Write your code here
        arr.sort()
        unfairness = []
        p1 = 0
        p2 = k - 1
        
        while p2 < len(arr):
            unfairness.append(arr[p2] - arr[p1])
            p1 += 1
            p2 += 1
        return min(unfairness)
        ****