Question

In a common backtracking approach to generate permutations of a string, elements are swapped to explore different arrangements. Complete the line that swaps characters s[index] and s[i] def recurPermute(index, s, ans):     if index == len(s):         ans.append("".join(s))         return     for i in range(index, len(s)):         s[index], s[i] = _________ # Line to complete (swap)         recurPermute(index + 1, s, ans)         s[index], s[i] = _________ # Line to complete (backtrack swap)

A s[i], s[index]
B s[index], s[index]
C s[i], s[i]
D s[index+1], s[i]
E s[i], s[index+1]
Practice Next

Hey! Ask a query