Don't understand the problem

  • 4

    it's said "Given an unsorted array, find the maximum difference between the successive elements in its sorted form."

    What does it mean by "difference"? What is the difference between the successive elements? What does "in its sorted form" mean?

  • 19

    "difference" between two elements A and B means the absolute value of (A - B).

    "in its sorted form" means we need to get the maximum gap in the global sorted order, not the the given unsorted array order.

    For example, given a array [1, 7, 3, 3], the expected result it 4, not (7 - 1) = 6.

    We need to sort the the array into [1, 3, 3, 7], and get the maximum gap between the successive elements in this sorted array, which is (7 - 3) = 4.

  • 0

    Even if it is not an absolute value, we can know the negative ones must be smaller and we just need the non-negative ones. ;-)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.