to achieve this my friend suggested me this logic.. rotate the string and then print it and swap the characters with another.. example : input is "abc" rotating : cab bca abc now swapping the first character with second so now our new string becomes 'bac' again rotating cba acb bac like this i got permutations! but what if the length of the input is greater than 3 ? I tried to achive my goal with 4 length of string with the same logic.. but I am getting 4 duplicate values as output instead of real permutations. how to solve this problem? my attempt : https://code.sololearn.com/cw44n4fGvSWu/?ref=app
9/10/2021 6:38:32 PM
Ratnapal Shende5 Answers
New AnswerNick I want all possible permutations...like I described in description.. for "abcd" their are 24 possible permutations (non repeated) nPr=n! ------ (n-r)!
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message