Created
December 4, 2019 12:28
-
-
Save mk6619/27d764e2e5fb25824fb9f46b70009fc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| /** | |
| We could have done this problem by coounting the occurence of elements | |
| */ | |
| int main() { | |
| int testCases; | |
| cin>>testCases; | |
| for(int i = 0 ; i < testCases; i++) { | |
| int n; | |
| cin>>n; | |
| int arr[n]; | |
| for(int j =0 ; j < n ; j++) { | |
| cin>>arr[j]; | |
| } | |
| int pointer = 0, temp; | |
| for(int j =0 ; j < n ; j++) { | |
| if(arr[j]==0) { | |
| temp = arr[j]; | |
| arr[j]=arr[pointer]; | |
| arr[pointer]= temp; | |
| pointer++; | |
| } | |
| } | |
| for(int j =0 ; j < n ; j++) { | |
| if(arr[j]==1) { | |
| temp = arr[j]; | |
| arr[j]=arr[pointer]; | |
| arr[pointer]= temp; | |
| pointer++; | |
| } | |
| } | |
| for(int j =0 ; j < n ; j++) { | |
| cout<<arr[j]<<" "; | |
| } | |
| cout<<endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment