diff --git a/C++/minimum-right-shifts-to-sort-the-array.cpp b/C++/minimum-right-shifts-to-sort-the-array.cpp new file mode 100644 index 0000000..a3dfbd3 --- /dev/null +++ b/C++/minimum-right-shifts-to-sort-the-array.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + int minimumRightShifts(vector& nums) { + for (int i = 0; i < nums.size(); ++i) { + if (is_sorted(nums.begin(), nums.end())) + return i; + int last_element = nums.back(); + nums.pop_back(); + nums.insert(nums.begin(), last_element); + } + return -1; + } +}; \ No newline at end of file