Java - Checking the distance between the points
Intuition\nTo solve this problem, one approach is to sort the positions of the stones in ascending order to understand their relative positions. This allows for
# Intuition\nTo solve this problem, one approach is to sort the positions of the stones in ascending order to understand their relative positions. This allows for a clear analysis of the distances between adjacent stones.\n\n\n# Approach\nThe first step in the approach involves sorting the positions of the stones. After sorting, we can examine the distances between adjacent stones. If the distances between adjacent stones are both 1, then no moves are needed to arrange the stones optimally. Otherwise, we need to calculate the minimum and maximum moves required based on the configurations of the stones.\n\n\n# Complexity\n- Time complexity: $$O(n log(n)) = O(3 log(3)) = O(1.5)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] numMovesStones(int a, int b, int c) {\n        int[] arr = new int[] {a, b, c};\n        Arrays.sort(arr);\n        int x = arr[0];\n        int y = arr[1];\n        int z = arr[2];\n        if (y - x == 1 && z - y == 1) return new int[]{0, 0};\n        return new int[] {\n            getMin(x, y, z), getMax(x, y, z)\n        };\n    }\n\n    public int getMin(int x, int y, int z) {\n        if (y - x == 1 || z - y == 1) return 1;\n        if (y - x == 2 || z - y == 2) return 1;\n        return 2;\n    }\n\n    public int getMax(int x, int y, int z) {\n        return (y-x)-1 + (z-y)-1;\n    }\n}\n```
['Math', 'Brainteaser', 'Java']