Beats 100 % || Optimized Code || Easy to understand
\n# Approach\n Describe your approach to solving the problem. \n1. Put all three into vector\n2. Sort it as size is 3 only O(1) time\n3. now check the differenc
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Put all three into vector\n2. Sort it as size is 3 only O(1) time\n3. now check the differences between the values and put the value of mini accordingly\n4. Maximum value = abs( D1 + D2 +2);\n5. Return ans.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code\n```\nclass Solution {\npublic:\n   vector<int> numMovesStones(int a, int b, int c) {\n        vector<int> v = {a, b, c};\n        sort(v.begin(), v.end());\n        \n        int d1 = v[1] - v[0];\n        int d2 = v[2] - v[1];\n\n        int mini, maxi;\n\n        // Minimum moves calculation\n        if (d1 == 1 && d2 == 1) {\n            mini = 0;\n        } else if (d1 <= 2 || d2 <= 2) {\n            mini = 1;\n        } else {\n            mini = 2;\n        }\n\n        // Maximum moves calculation\n        maxi = d1 + d2 - 2;\n\n        return {mini, maxi};\n    }\n};\n```
['C++']