title: How do I find all possible permutations of a string with only single swap?
body: <p>The complexity should be O(n) where n is length of string.
  Ex: For 'abc', answer is 'bac', 'cba', 'acb'.
  'bca' and 'cab' should not be in the list as two swaps are required to convert it to 'abc'.</p>
  
  <p>I have made a O(n<sup>2</sup>) algorithm but it is very slow.</p>
  
  <pre><code>def f(s):
      temp=list(s)
      l=[]
      for i in range(len(s)):
          for j in range(len(s)):
              temp=list(s)
              temp[i],temp[j]=temp[j],temp[i]
              l.append("".join(str(i) for i in temp))
      print set(l)
  </code></pre>