You are not logged in. Please login at to post your questions!


SHELPASS - Editorial

Sheldon Password


Tags: Permutation.

Author: Shami.

This problem is a fancy way of asking to compute Kth permutation given a starting string. Since the maximum length of string is only 9, we can map the letters to digits and work with numbers (if that is more comfortable).

How to find the next permutation?

This Wiki article describes the following steps:

  1. Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
  2. Find the largest index l greater than k such that a[k] < a[l].
  3. Swap the value of a[k] with that of a[l].
  4. Reverse the sequence from a[k + 1] up to and including the final element a[n].

However, if you are programming in C++, you’ll be happy to know there is a function that just does that!

asked 12 Jan, 14:18

mmmreddy's gravatar image

accept rate: 0%

edited 12 Jan, 14:25

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 12 Jan, 14:18

question was seen: 94 times

last updated: 12 Jan, 14:25