Skip to content

Commit

Permalink
Merge pull request #204 from Avnee29/patch-3
Browse files Browse the repository at this point in the history
Two-pass approach used to solve the problem
  • Loading branch information
Gyanthakur authored Oct 28, 2024
2 parents 83abe28 + 22fb851 commit 64e3a28
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions october_2024/POTD_24_October_2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution{
public:
vector<int>modifyAndRearrangeArray(vector<int> &arr){
//Complete the function
int j=0;
for(int i=0;i<arr.size();i++){
if(arr[i]) arr[j++]=(i<arr.size()-1 && arr[i]==arr[i+1])?arr[i++]*2:arr[i];
}
fill(arr.begin()+j,arr.end(),0);
return arr;
}
};

0 comments on commit 64e3a28

Please sign in to comment.