Skip to content

Commit

Permalink
Merge pull request #209 from gautamjag7/gautamjag7-patch-9
Browse files Browse the repository at this point in the history
added solution for GFG_POTD_25-10-2024_Alternative_Sorting
  • Loading branch information
Gyanthakur authored Oct 25, 2024
2 parents 6c5c8a2 + 0f7b424 commit 1a3892e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions october_2024/GFG_POTD_25-10-2024_Alternative_Sorting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
vector<int> alternateSort(vector<int>& arr) {
sort(arr.begin(),arr.end());
int n=arr.size();
vector<int>ans;
int i=0,j=n-1;
while(i<j)
{
ans.push_back(arr[j--]);
ans.push_back(arr[i++]);
}
if(n%2!=0)
ans.push_back(arr[i]);
return ans;
}
};

0 comments on commit 1a3892e

Please sign in to comment.