Skip to content

Commit

Permalink
Added solution for minimum right shifts to sort the array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtha-Sunil committed Oct 30, 2024
1 parent a3fac8b commit 0a7064b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions C++/minimum-right-shifts-to-sort-the-array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public:
int minimumRightShifts(vector<int>& 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;
}
};

0 comments on commit 0a7064b

Please sign in to comment.