Tag Archive for 'map'

Programming exercise: permutations of a string

[Permalink]

The problem is to implement a function that outputs all possible permutations of the characters in a string. Unlike combinations, two permutations are considered distinct if they contain the same characters, but in a different order. Also, for the purposes of this exercise, each occurrence of a repeated character is considered to be a distinct character. That is, if the input is “aaa”, the output should be six repetitions of “aaa”. The permutations may be output in any order.

This exercise, like the previous one on combinations of a string, is from the book Programming Interviews Exposed by John Mongan and Noah Suojanen[1]\(\)… » [Expand post] [Permalink]

0 Comments

Programming exercise: combinations of a string

[Permalink]

The problem is to implement a function that outputs all possible combinations of the characters in a string (with length ranging from one to the length of the string). Unlike permutations, two combinations are considered to be the same if they contain the same characters, but in a different order. Another way to define the problem is to find the power set of the characters of the string (excluding the empty set).

Like the previous exercise, this one is also from the book Programming Interviews Exposed by John Mongan and Noah Suojanen[1]\(\)… » [Expand post] [Permalink]

2 Comments