Statistics

Problem Statement for "RingLex"

Problem Statement

Hero has an infinite periodic string t. You are given the String s that is the period of Hero's string. For example, if s = "abc", Hero's actual string is t = "abcabcabcabc..." Let n be the length of string s. Hero is now going to use the infinite string t to generate a new n-character string by doing the following steps:
  1. He will choose an offset: a non-negative integer x.
  2. He will choose the length of a step: a prime number p that is less than n.
  3. The new string will consists of the first n characters we can read in the string t if we start at the index x and after each character we move p positions to the right.
Formally, Hero's new string will consist of the following characters, in order: t[x], t[x + p], t[x + 2*p], ..., t[x + (n-1)*p]. Find and return the lexicographically smallest string Hero can produce.

Definition

Class:
RingLex
Method:
getmin
Parameters:
String
Returns:
String
Method signature:
String getmin(String s)
(be sure your method is public)

Notes

  • Given two distinct strings of the same length, the lexicographically smaller one is the one that has a smaller character at the first position where they differ.
  • A positive integer p is a prime if it has exactly two distinct divisors: 1 and p. Note that the number 1 is not a prime.

Constraints

  • s will contain between 3 and 50 characters, inclusive.
  • Each character in s will be between 'a' and 'z', inclusive.

Examples

  1. "cba"

    Returns: "abc"

    Hero should choose the offset x=2 and the step p=2. The resulting string is t[2]+t[4]+t[6] = 'a'+'b'+'c' = "abc".

  2. "acb"

    Returns: "abc"

    Here, Hero should choose x=0 and p=2.

  3. "abacaba"

    Returns: "aaaabcb"

  4. "aaabb"

    Returns: "aabab"

  5. "azzzabbb"

    Returns: "abazabaz"

    Note that Hero cannot choose x=0 and p=4, because 4 is not a prime number.

  6. "abbaac"

    Returns: "aaaaaa"

  7. "fsdifyhsoe"

    Returns: "dehifsfsoy"

  8. "ikeff"

    Returns: "efkfi"

  9. "nimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpva"

    Returns: "aaefascrkvoeflyskpcostkwmvbopxzviuzpyfnsnjxdgxe"

  10. "ygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhms"

    Returns: "aasqfjrueppnophqyujomyrplvxhompvymnljvwygqboiwwexl"

  11. "bxcoksfzkvatxdknlyjyhfixjswn"

    Returns: "adlyisbofvxnjfjncsktkyhxwxkz"

  12. "ufnuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvs"

    Returns: "aamuyngymzzgqpqrvocsodukdfeintuultxyexhiznorkjzowb"

  13. "psajlfvgubfaaovlzylntrkdcpwsrtesjwhdizcobzcnfwlqij"

    Returns: "aanhpzgioerajfdwyujbskolwislbpzjdvflzrnfscwclvqctt"

  14. "dwvxhrcbldvgyl"

    Returns: "bcrhxvwdlygvdl"

  15. "busbmborxtl"

    Returns: "bblmtbxsruo"

  16. "smpxohgmgnkeufdxotogbgxpeyanfetcukepzshkljugggekjd"

    Returns: "aczjemgeogaczjemgeogaczjemgeogaczjemgeogaczjemgeog"

  17. "jenpevqgxiepjsrdzjazujllchhbfqmkimwzobiwy"

    Returns: "abdwjkifqhpljzizzsieqgheleuwjormpmxbvcnjy"

  18. "duunfsksrsrtekmqdcyzjeeuhmsrqcozijipfioneeddps"

    Returns: "cdceehsfzuzmdssoefjdsqteukpyuokdmrijniqprrnesi"

  19. "navymmtatbdzqsoemuvnpppsuacbazuxmhec"

    Returns: "aaxeamadsmnpaaxeamadsmnpaaxeamadsmnp"

  20. "legrpunkdmbppweq"

    Returns: "bedqnwppgmlkeupr"

  21. "joparmowzdqyoxytjbbhawdydcprjbxphoohpkwqyuhrqzhnbn"

    Returns: "aakrwwmdqoyywduzchdprqrqyjzobhxxnypbthnjojboobhphp"

  22. "vqnqqlrzjpxiogvliexdzuzosrkrusvojbrzmwzpowkjilefra"

    Returns: "aejowrourzdigxzqqrlkpmbvrsuxloprqvfiwzzjskozevijln"

  23. "digpn"

    Returns: "dgnip"

  24. "uhgxpqnjwjmwaxxmnsnhhlqqrzudltfzotcjtnzxuglsdsmzcn"

    Returns: "aghnljtmdqgzmxnzuqcxllutwnnsrxowuhcdnjxsqhfjzsmzpt"

  25. "kvfajfrmxothowkbjzwuc"

    Returns: "acjoxjkzwofvwktrfubhm"

  26. "jfrimpmyhchzriwkbarxbgfcbceyhjugi"

    Returns: "abcejirphzwabcejirphzwabcejirphzw"

  27. "tbvtrehbbcpxifbxvfbcgkcfqckcotzgku"

    Returns: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"

  28. "jrmbsztsshfroefwsjrxjhguzyupzwweiqurpixiqflduuveoo"

    Returns: "bfjzexumhsuwiurswgwpdjsfhzrlotejpufozoxuqqesrryiiv"

  29. "cudhnefnjhaimuczfskuiduburiswtbrecuykabfcvkdzeztoi"

    Returns: "aacftdrodzscukheewuutidffmyjrnscbzukzbiunbhiiuekvc"

  30. "kuhjzefczzzbfkqdpqzikfob"

    Returns: "bfkkjzqkcqfzbzuzdoefihzp"

  31. "dhthxdjgkjelrlpaxamceroswitdptpcclifkeljytihrcqayb"

    Returns: "aacrsidtclfejthcabhhdgjllaacrsidtclfejthcabhhdgjll"

  32. "fxnxvgzedyyhngyc"

    Returns: "cngdhyxveygfxzyn"

  33. "udmphmeckotr"

    Returns: "cemhpmdurtok"

  34. "spofghfozqvlqfxwwkmfxdyygmdcaszsgovsodkjghcwmbmxrm"

    Returns: "abqsmfzxxsrwgmwoskvpmsofofxdgdkhyjfygoghzmcqdwvcml"

  35. "yfyqgajqkcklznayxqkqoyzwmy"

    Returns: "aazngyzqolyqkfkcyqkyxqmyjw"

  36. "zazcpkhktkydziv"

    Returns: "ackkkdizzphtyzv"

  37. "ypurfmbisgekyrgzvxdhpoamvafyrarxsvkhtqdihersigbhzj"

    Returns: "aahvreifpzgritvryvodzygbryhiedhsafmpxgksmujbshqkxr"

  38. "jxmmyspnaraewkegjccvhhrjvbjtsqdjootgpknfpfycgfieow"

    Returns: "aawejchrvjsdotpnpygiojmypaawejchrvjsdotpnpygiojmyp"

  39. "wwwpzsqme"

    Returns: "eqzwwmspw"

  40. "gepspxnvjiupalyynmkmnuvklhsecdwracgfmzkgipdfodkjmj"

    Returns: "adjugjukmjahkeyeisnddxkrovnckivfmplzglsgpycppmwfnm"

  41. "iqpuoqhimvfvuzwyvijgfullkjduhsjaf"

    Returns: "aipohmfuwvjflkdhjfquqivvzyiguljus"

  42. "lkmfqrmyjfjnhhssqctydteamdcjbprhtnegyiwxgcjwlg"

    Returns: "abnwwmyhcejtijkmnqtchyclrjsddrgggqfsympexlfjht"

  43. "meaearwtvj"

    Returns: "aawvmaawvm"

  44. "baoiojlwhypnvruihoswkifygtydhacwyhsgewzmtgonz"

    Returns: "aasgwggrcowehtouwikwyyniyoizpdzhhjfmnhboslytv"

  45. "jhga"

    Returns: "aghj"

  46. "asdfg"

    Returns: "adgsf"

  47. "dhkajshdkjash"

    Returns: "aajsshhddhkkj"

  48. "acccaccc"

    Returns: "acacacac"

  49. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

    Returns: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

  50. "bcabcbbbcbbcbcbcbcbbcbaaabcbacbaaca"

    Returns: "aaaabccbccaccabbbbbcbbabbcccbbcbbab"

  51. "zzzzzzzzzz"

    Returns: "zzzzzzzzzz"


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: