void print(vector<int>& v){
        for(auto ele : v)
            cout << ele << " ";
        cout<< endl;
    void backtrack(int index, vector<int> ans){
        if(index == (ans.size() - 1)){
        for(int i = index; i < ans.size(); i++){
            swap(ans[index], ans[i]);
            backtrack(index+1, ans);
            swap(ans[index], ans[i]);
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter