Sir please clarify the above question

string s = “bca”;

do {
cout << s << ’ ';
} while(next_permutation(s.begin(), s.end()));

cout << s;
What is the output of the given code?

hello @Kshubham1532
are u aware of next_permuation function ?

Yes,but how it is printing abc at last?

while loop stop when next_permuatation will return false.
it return false when next lexicographical string is not possible and in that case it will return smallest string possible.
so in our case smallest string is abc.

image

thankyou so much
i got it!