ProgrammingVery hardCAT · MBA placement
The number of distinct arrangements (permutations of the letters, with identical letters not counted twice) of the string "AABBC" is computed by the procedure below. What is printed?
The number of distinct arrangements (permutations of the letters, with identical letters not counted twice) of the string "AABBC" is computed by the procedure below. What is printed?
count the permutations of the 5 positions and divide by the factorials of the repeat counts Print result
- A. 120
- B. 60
- C. 30
- D. 6
Correct answer: C. 30
Five positions with A twice, B twice and C once give 5!/(2! 2! 1!) = 30 distinct strings. Treating all letters as distinct gives 120, dividing only by one repeat count gives 60, and counting arrangements of only four letters gives 6.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The string "Programming Language" is taken in lowercase and the procedure below counts its vowels (a, e, i, o, u). What is printed? count…
- For the bracket string "(()(()))", the procedure below tracks the nesting depth and prints the maximum depth reached. What is printed?…
- Longest common prefix of the words "flower", "flow" and "flight" is found by comparing characters column by column until a mismatch. The…
- The words of "the sky is blue" are reversed in order (the words themselves are kept). The procedure below does this and prints the result…
- The string "bananana" is searched for "ana" with overlapping occurrences allowed. The procedure below counts the start positions of…
- Strings are compressed in place by writing each run of equal characters as the character followed by the run length (a count of 1 is…