Problem Statement
- He will choose an offset: a non-negative integer x.
- He will choose the length of a step: a prime number p that is less than n.
- 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.
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
"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".
"acb"
Returns: "abc"
Here, Hero should choose x=0 and p=2.
"abacaba"
Returns: "aaaabcb"
"aaabb"
Returns: "aabab"
"azzzabbb"
Returns: "abazabaz"
Note that Hero cannot choose x=0 and p=4, because 4 is not a prime number.
"abbaac"
Returns: "aaaaaa"
"fsdifyhsoe"
Returns: "dehifsfsoy"
"ikeff"
Returns: "efkfi"
"nimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpva"
Returns: "aaefascrkvoeflyskpcostkwmvbopxzviuzpyfnsnjxdgxe"
"ygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhms"
Returns: "aasqfjrueppnophqyujomyrplvxhompvymnljvwygqboiwwexl"
"bxcoksfzkvatxdknlyjyhfixjswn"
Returns: "adlyisbofvxnjfjncsktkyhxwxkz"
"ufnuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvs"
Returns: "aamuyngymzzgqpqrvocsodukdfeintuultxyexhiznorkjzowb"
"psajlfvgubfaaovlzylntrkdcpwsrtesjwhdizcobzcnfwlqij"
Returns: "aanhpzgioerajfdwyujbskolwislbpzjdvflzrnfscwclvqctt"
"dwvxhrcbldvgyl"
Returns: "bcrhxvwdlygvdl"
"busbmborxtl"
Returns: "bblmtbxsruo"
"smpxohgmgnkeufdxotogbgxpeyanfetcukepzshkljugggekjd"
Returns: "aczjemgeogaczjemgeogaczjemgeogaczjemgeogaczjemgeog"
"jenpevqgxiepjsrdzjazujllchhbfqmkimwzobiwy"
Returns: "abdwjkifqhpljzizzsieqgheleuwjormpmxbvcnjy"
"duunfsksrsrtekmqdcyzjeeuhmsrqcozijipfioneeddps"
Returns: "cdceehsfzuzmdssoefjdsqteukpyuokdmrijniqprrnesi"
"navymmtatbdzqsoemuvnpppsuacbazuxmhec"
Returns: "aaxeamadsmnpaaxeamadsmnpaaxeamadsmnp"
"legrpunkdmbppweq"
Returns: "bedqnwppgmlkeupr"
"joparmowzdqyoxytjbbhawdydcprjbxphoohpkwqyuhrqzhnbn"
Returns: "aakrwwmdqoyywduzchdprqrqyjzobhxxnypbthnjojboobhphp"
"vqnqqlrzjpxiogvliexdzuzosrkrusvojbrzmwzpowkjilefra"
Returns: "aejowrourzdigxzqqrlkpmbvrsuxloprqvfiwzzjskozevijln"
"digpn"
Returns: "dgnip"
"uhgxpqnjwjmwaxxmnsnhhlqqrzudltfzotcjtnzxuglsdsmzcn"
Returns: "aghnljtmdqgzmxnzuqcxllutwnnsrxowuhcdnjxsqhfjzsmzpt"
"kvfajfrmxothowkbjzwuc"
Returns: "acjoxjkzwofvwktrfubhm"
"jfrimpmyhchzriwkbarxbgfcbceyhjugi"
Returns: "abcejirphzwabcejirphzwabcejirphzw"
"tbvtrehbbcpxifbxvfbcgkcfqckcotzgku"
Returns: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
"jrmbsztsshfroefwsjrxjhguzyupzwweiqurpixiqflduuveoo"
Returns: "bfjzexumhsuwiurswgwpdjsfhzrlotejpufozoxuqqesrryiiv"
"cudhnefnjhaimuczfskuiduburiswtbrecuykabfcvkdzeztoi"
Returns: "aacftdrodzscukheewuutidffmyjrnscbzukzbiunbhiiuekvc"
"kuhjzefczzzbfkqdpqzikfob"
Returns: "bfkkjzqkcqfzbzuzdoefihzp"
"dhthxdjgkjelrlpaxamceroswitdptpcclifkeljytihrcqayb"
Returns: "aacrsidtclfejthcabhhdgjllaacrsidtclfejthcabhhdgjll"
"fxnxvgzedyyhngyc"
Returns: "cngdhyxveygfxzyn"
"udmphmeckotr"
Returns: "cemhpmdurtok"
"spofghfozqvlqfxwwkmfxdyygmdcaszsgovsodkjghcwmbmxrm"
Returns: "abqsmfzxxsrwgmwoskvpmsofofxdgdkhyjfygoghzmcqdwvcml"
"yfyqgajqkcklznayxqkqoyzwmy"
Returns: "aazngyzqolyqkfkcyqkyxqmyjw"
"zazcpkhktkydziv"
Returns: "ackkkdizzphtyzv"
"ypurfmbisgekyrgzvxdhpoamvafyrarxsvkhtqdihersigbhzj"
Returns: "aahvreifpzgritvryvodzygbryhiedhsafmpxgksmujbshqkxr"
"jxmmyspnaraewkegjccvhhrjvbjtsqdjootgpknfpfycgfieow"
Returns: "aawejchrvjsdotpnpygiojmypaawejchrvjsdotpnpygiojmyp"
"wwwpzsqme"
Returns: "eqzwwmspw"
"gepspxnvjiupalyynmkmnuvklhsecdwracgfmzkgipdfodkjmj"
Returns: "adjugjukmjahkeyeisnddxkrovnckivfmplzglsgpycppmwfnm"
"iqpuoqhimvfvuzwyvijgfullkjduhsjaf"
Returns: "aipohmfuwvjflkdhjfquqivvzyiguljus"
"lkmfqrmyjfjnhhssqctydteamdcjbprhtnegyiwxgcjwlg"
Returns: "abnwwmyhcejtijkmnqtchyclrjsddrgggqfsympexlfjht"
"meaearwtvj"
Returns: "aawvmaawvm"
"baoiojlwhypnvruihoswkifygtydhacwyhsgewzmtgonz"
Returns: "aasgwggrcowehtouwikwyyniyoizpdzhhjfmnhboslytv"
"jhga"
Returns: "aghj"
"asdfg"
Returns: "adgsf"
"dhkajshdkjash"
Returns: "aajsshhddhkkj"
"acccaccc"
Returns: "acacacac"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"bcabcbbbcbbcbcbcbcbbcbaaabcbacbaaca"
Returns: "aaaabccbccaccabbbbbcbbabbcccbbcbbab"
"zzzzzzzzzz"
Returns: "zzzzzzzzzz"