Permutations of Strings

  • + 10 comments

    Spoiler alert: https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order

    My thought on this problem: It's too hard to come up with the algorithm without looking at the definition/wiki of permutation (I spent 3+ hours thinking before reading the wiki); with the definition, this problem takes 15 mins max coding time. In fact, it's implemented as "std::next_permutation" in the "algorithm" library in C++, which kinda labels its difficulty. http://en.cppreference.com/w/cpp/algorithm/next_permutation Not to mention my implementation based on the wiki algorithm was not as elegant as that from the algorithm library in C++. Anyway, if this question is really just about implementing the permutation algorithm as a practice, it should provide hints to the definition/wiki; otherwise, the problem difficulty level should be at least Hard for one to come up with an algorithm from scratch.