Statistics

Problem Statement for "TranspositionKey"

Problem Statement

Some coding systems involve using a set of known text to create a transposition key that determines how a message will be scrambled. Unfortunately, humans are error prone and frequently make mistakes, so it will be your job to write a function to do it properly.

To create a transposition key from text, take the first letter in the alphabet that appears in the text. Number each occurrence of this letter in the text from left to right, starting with 1, 2, 3, etc. Ignore case. Then take the next letter in the alphabet that appears in the text and again number each occurrence of this letter from left to right, continuing the numbering from where you previously left off. Continue until done. The following example illustrates:

Quoth the raven, Nevermore.

The first letter in the alphabet which appears in this text is a.  Thus:

                            1
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

The next letter that appears is e.  Numbering the e's, we get:

                      2     1     3        4     5              6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Next comes h:

             7     8  2     1     3        4     5              6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Continuing through the last letter, v, gives the finished key:

14 20 12 18  7 19  8  2 15  1 21  3 10 11  4 22  5 16  9 13 17  6
 Q  U  O  T  H  T  H  E  R  A  V  E  N  N  E  V  E  R  M  O  R  E

Your function should return the numbers across the top.

Definition

Class:
TranspositionKey
Method:
makeKey
Parameters:
String
Returns:
int[]
Method signature:
int[] makeKey(String text)
(be sure your method is public)

Constraints

  • - text will have a length from 0 to 50 characters, inclusive.
  • - text will contain only letters, spaces, commas, and periods.

Examples

  1. "aaa"

    Returns: {1, 2, 3 }

    Note we go from left to right when seeing duplicates of the same letter.

  2. "ywedkcjs"

    Returns: {8, 7, 3, 2, 5, 1, 4, 6 }

    No duplicates here.

  3. "Quoth the raven, Nevermore."

    Returns: {14, 20, 12, 18, 7, 19, 8, 2, 15, 1, 21, 3, 10, 11, 4, 22, 5, 16, 9, 13, 17, 6 }

    This is the example from the problem statement.

  4. "Fuzzy wuzzy was a bear."

    Returns: {6, 9, 15, 16, 13, 11, 10, 17, 18, 14, 12, 1, 8, 2, 4, 5, 3, 7 }

  5. "UCC Event"

    Returns: {7, 1, 2, 3, 8, 4, 5, 6 }

  6. "I think, therefore I am."

    Returns: {8, 17, 6, 9, 13, 11, 18, 7, 2, 15, 3, 5, 14, 16, 4, 10, 1, 12 }

  7. ""

    Returns: { }

  8. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }

  9. "aaaaaaaaaaaaaaaaaaaa aaaaaaa,aaaaaaaaaaaaaaaaaaaaa"

    Returns: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48 }

  10. ",,,...,, "

    Returns: { }

  11. "AaAaBbAaBb"

    Returns: {1, 2, 3, 4, 7, 8, 5, 6, 9, 10 }

  12. "saKhzSOiJDc"

    Returns: {9, 1, 7, 4, 11, 10, 8, 5, 6, 3, 2 }

  13. "sbRT CWhIzWgiqwqoggHqPzqBsLXHL"

    Returns: {21, 1, 20, 23, 3, 24, 7, 10, 28, 25, 4, 11, 16, 26, 17, 14, 5, 6, 8, 18, 15, 29, 19, 2, 22, 12, 27, 9, 13 }

  14. "EX DSQhuYxlyxDj,IadyhbVqdgfRIv,a BSIlneaHrHOFW"

    Returns: {10, 37, 6, 31, 27, 15, 33, 40, 38, 23, 41, 39, 7, 22, 19, 1, 8, 42, 16, 4, 34, 28, 9, 14, 12, 29, 20, 35, 2, 5, 32, 21, 24, 25, 11, 3, 17, 30, 18, 26, 13, 36 }

  15. "nXtC jRQiCL"

    Returns: {6, 10, 9, 1, 4, 8, 7, 3, 2, 5 }

  16. "qpPmizK wqaSa CrvTGlGexyTtBvjpoF"

    Returns: {18, 15, 16, 13, 9, 30, 11, 27, 19, 1, 21, 2, 4, 20, 25, 22, 7, 12, 8, 5, 28, 29, 23, 24, 3, 26, 10, 17, 14, 6 }

  17. "ItpwFeU ZK ahAgfaO fYLxWSty"

    Returns: {10, 16, 14, 19, 5, 4, 18, 24, 11, 1, 9, 2, 8, 6, 3, 13, 7, 22, 12, 21, 20, 15, 17, 23 }

  18. "SGBUxRISzqurqlU xMAPDPa"

    Returns: {15, 5, 3, 17, 20, 13, 6, 16, 22, 11, 18, 14, 12, 7, 19, 21, 8, 1, 9, 4, 10, 2 }

  19. "zphxarpbgHE hiPx"

    Returns: {15, 9, 5, 13, 1, 12, 10, 2, 4, 6, 3, 7, 8, 11, 14 }

  20. "lpZJurv ZZhxEOvfK hf"

    Returns: {8, 10, 16, 6, 12, 11, 13, 17, 18, 4, 15, 1, 9, 14, 2, 7, 5, 3 }

  21. "Y,EQKeQ.TP HBXfB.F q ASIibxN"

    Returns: {22, 5, 15, 12, 6, 16, 19, 14, 9, 2, 20, 7, 3, 8, 17, 1, 18, 10, 11, 4, 21, 13 }

  22. "XknStMqVykMf GKkpDvQeKxjt"

    Returns: {22, 6, 13, 17, 18, 11, 15, 20, 24, 7, 12, 3, 4, 8, 9, 14, 1, 21, 16, 2, 10, 23, 5, 19 }

  23. "Xl mnlCj kNuMLtlGaqK,zHcyXB vMr"

    Returns: {24, 10, 14, 17, 11, 3, 7, 8, 18, 22, 15, 12, 21, 13, 5, 1, 19, 9, 27, 6, 4, 26, 25, 2, 23, 16, 20 }

  24. "dQtFZL fcTKfW"

    Returns: {2, 8, 9, 3, 12, 7, 4, 1, 10, 6, 5, 11 }

  25. "vkbyEWyifddXtPkGtoxJR XoL eKnkohF,hWa IVLzpPgBW"

    Returns: {33, 17, 2, 41, 6, 35, 42, 14, 8, 4, 5, 38, 31, 27, 18, 10, 32, 24, 39, 16, 30, 40, 25, 21, 7, 19, 23, 20, 26, 12, 9, 13, 36, 1, 15, 34, 22, 43, 28, 29, 11, 3, 37 }

  26. " WeanNizNsmIxn u RvnNkwgb WLHHKdxOQF"

    Returns: {27, 4, 1, 15, 16, 9, 32, 17, 24, 14, 10, 30, 18, 25, 23, 26, 19, 20, 11, 28, 6, 2, 29, 13, 7, 8, 12, 3, 31, 21, 22, 5 }

  27. "zxVmImO.cc.uakog,mq"

    Returns: {16, 15, 14, 7, 5, 8, 10, 2, 3, 13, 1, 6, 11, 4, 9, 12 }

  28. "zLPLnFlck.ZjvgCZaBF,ih.aXWmba zgeWTnhJ"

    Returns: {31, 19, 25, 20, 23, 9, 21, 6, 18, 32, 16, 27, 11, 7, 33, 1, 4, 10, 15, 13, 2, 30, 28, 22, 5, 3, 34, 12, 8, 29, 26, 24, 14, 17 }

  29. "DBrUcDU.ziOF hsFSMusRYJBmFxFYMTwRCB wMbXDXsyLw ,r"

    Returns: {7, 1, 23, 32, 5, 8, 33, 44, 15, 22, 10, 14, 27, 11, 28, 18, 34, 29, 24, 41, 16, 2, 19, 12, 38, 13, 42, 20, 31, 35, 25, 6, 3, 36, 21, 4, 39, 9, 40, 30, 43, 17, 37, 26 }

  30. "RAbsVlkwpmXKPfmPWtzgvOFpWpzlQvuHySGMwE VWFGfDNtwFj"

    Returns: {30, 1, 2, 31, 36, 17, 15, 40, 24, 19, 46, 16, 25, 5, 20, 26, 41, 33, 48, 10, 37, 23, 6, 27, 42, 28, 49, 18, 29, 38, 35, 13, 47, 32, 11, 21, 43, 4, 39, 44, 7, 12, 8, 3, 22, 34, 45, 9, 14 }

  31. "tDDX D qVkr.gywQQ ZaXSydJqHfmJ DfmBrEbXCQFnPjXdMns"

    Returns: {36, 5, 6, 39, 7, 27, 37, 20, 32, 15, 43, 38, 28, 29, 45, 1, 40, 34, 44, 8, 17, 30, 16, 12, 21, 18, 9, 13, 22, 2, 33, 11, 3, 41, 4, 31, 14, 24, 26, 19, 42, 10, 23, 25, 35 }

  32. " xWkLbKeOK VELonYzxFLudWJSjiyrMzwyNElzafheMNG Acg "

    Returns: {39, 36, 18, 21, 3, 19, 6, 30, 20, 35, 7, 22, 31, 27, 41, 44, 40, 10, 23, 34, 5, 37, 16, 33, 17, 15, 42, 32, 25, 45, 38, 43, 28, 8, 24, 46, 1, 11, 14, 9, 26, 29, 12, 2, 4, 13 }

  33. ",jUigHTAbywgkb CdL,kBeYSdmhQQNRHC sieNRFqlXhnAyqPD"

    Returns: {22, 41, 20, 14, 16, 40, 1, 3, 44, 42, 15, 23, 4, 6, 8, 25, 24, 5, 11, 45, 38, 9, 27, 17, 32, 33, 28, 36, 18, 7, 39, 21, 12, 29, 37, 13, 34, 26, 43, 19, 30, 2, 46, 35, 31, 10 }

  34. "Wud zYKCFzfCoOgpenoTcQyxyUHwjcswAMvbiFDTYcIXfo JA,"

    Returns: {37, 34, 9, 46, 42, 22, 4, 12, 47, 13, 5, 25, 26, 16, 29, 11, 24, 27, 32, 6, 30, 43, 40, 44, 35, 17, 38, 20, 7, 31, 39, 1, 23, 36, 3, 18, 14, 10, 33, 45, 8, 19, 41, 15, 28, 21, 2 }

  35. "aLB gG lCeRTXhGoBcXEGYkUz.HbSKX vlChuElog DdCFFfQw"

    Returns: {1, 27, 2, 17, 18, 28, 5, 11, 34, 36, 41, 22, 19, 31, 3, 6, 42, 12, 20, 44, 25, 37, 45, 23, 4, 35, 26, 43, 39, 29, 7, 24, 38, 13, 30, 32, 21, 9, 10, 8, 14, 15, 16, 33, 40 }

  36. "mZq wBgmBg,ZSwHTcqfey wndJVHSuzhLbc MzuABICEqGjMVn"

    Returns: {23, 43, 29, 39, 2, 13, 24, 3, 14, 44, 32, 40, 16, 34, 6, 30, 12, 10, 42, 41, 27, 9, 20, 37, 17, 33, 35, 45, 18, 22, 4, 7, 25, 46, 36, 1, 5, 19, 8, 11, 31, 15, 21, 26, 38, 28 }

  37. "hTAq qiCXmlZTLlWNwTJHi edqyr WfJqkNggZdrTJcHUgtvYT"

    Returns: {11, 32, 1, 26, 27, 14, 2, 43, 23, 20, 46, 33, 21, 22, 40, 24, 41, 34, 16, 12, 15, 6, 4, 28, 44, 30, 42, 7, 17, 29, 19, 25, 8, 9, 47, 5, 31, 35, 18, 3, 13, 38, 10, 36, 39, 45, 37 }

  38. "yrxLf.WbNMwwEAGcno,FusTgv GuJ DSidtQeENJFMR bEbAx"

    Returns: {44, 30, 42, 22, 13, 39, 3, 25, 23, 40, 41, 9, 1, 16, 6, 26, 28, 14, 36, 32, 34, 17, 38, 18, 37, 20, 7, 33, 19, 8, 35, 29, 10, 11, 27, 21, 15, 24, 31, 4, 12, 5, 2, 43 }

  39. "yEwSdFYQVhxhRQOtdabSLIkp pgBlTxjtRDxL.EYUAJbVgs CH"

    Returns: {45, 10, 41, 32, 7, 12, 46, 28, 39, 15, 42, 16, 30, 29, 25, 35, 8, 1, 3, 33, 22, 18, 21, 26, 27, 13, 4, 23, 36, 43, 19, 37, 31, 9, 44, 24, 11, 47, 38, 2, 20, 5, 40, 14, 34, 6, 17 }

  40. " i.nlpYHXtdWjBpOt.MWhdVD L.JUT k,eVPkGlTYEhQz VHrG"

    Returns: {13, 22, 18, 24, 40, 9, 39, 29, 2, 37, 14, 1, 25, 23, 30, 21, 38, 10, 3, 34, 4, 19, 15, 33, 31, 16, 5, 35, 26, 17, 7, 20, 32, 41, 6, 11, 27, 42, 36, 12, 28, 8 }

  41. "ssoleZM papPrDwyYFlZinTy d FI.uxXNgJ R. CoVKiJReZB"

    Returns: {30, 31, 22, 17, 6, 41, 19, 24, 1, 25, 26, 27, 4, 35, 38, 39, 8, 18, 42, 11, 20, 32, 40, 5, 9, 12, 33, 36, 37, 21, 10, 14, 28, 3, 23, 34, 16, 13, 15, 29, 7, 43, 2 }

  42. "your code.... is broken"

    Returns: {16, 9, 15, 12, 2, 10, 3, 4, 6, 14, 1, 13, 11, 7, 5, 8 }

  43. "so...,, whats up mate"

    Returns: {8, 6, 13, 4, 1, 10, 9, 12, 7, 5, 2, 11, 3 }

  44. "once upon a time"

    Returns: {9, 7, 2, 3, 13, 11, 10, 8, 1, 12, 5, 6, 4 }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: