Skip to content

Commit

Permalink
Create UniquePermutation.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartikay123 authored Oct 21, 2021
1 parent a221f33 commit a151e5a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions UniquePermutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;


// } Driver Code Ends
//User function Template for C++

class Solution {
public:
vector<vector<int>> uniquePerms(vector<int> arr ,int n) {
// code here
vector<vector<int>>ans;
sort(arr.begin(),arr.end());
do
{
ans.push_back(arr);
} while (next_permutation(arr.begin(),arr.end()));
return ans;
}
};



int main() {
int t;
cin >> t;
while (t--) {
int n;

cin>>n;
vector<int> arr(n);

for(int i=0 ; i<n ; i++)
cin>>arr[i];

Solution ob;
vector<vector<int>> res = ob.uniquePerms(arr,n);
for(int i=0; i<res.size(); i++)
{
for(int j=0; j<n; j++)
{
cout<<res[i][j]<<" ";
}
cout<<"\n";
}
}
return 0;
}

0 comments on commit a151e5a

Please sign in to comment.