Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 726 Bytes

14.md

File metadata and controls

32 lines (27 loc) · 726 Bytes

Permutation with Spaces

Practice
void find(int ind,vector<string>&ans,int flag ,string st,string s)
  {
      if(ind==s.size())
      {
          ans.push_back(st);
          return;
      }
      
      if(flag!=1)
      {
          st+=" ";
          flag=1;
          find(ind,ans,flag,st,s);
          st.pop_back();
      }
      
      st.push_back(s[ind]);
      flag=0;
      find(ind+1,ans,flag,st,s);
  }

  vector<string> permutation(string s){
      vector<string> ans;
      string st;
      
      find(0,ans,1,st,s);
      return ans;
  }