TopCoder problem "AnagramList" used in SRM 337 (Division II Level Three)



Problem Statement

    

An anagram of a string is any string that contains the same characters in any order. For example, the anagrams of "tree" are, in alphabetical order: "eert", "eetr", "eret", "erte", "eter", "etre", "reet", "rete", "rtee", "teer", "tere" and "tree".

You will be given a String s and an int i. Return the ith (0-based) anagram of s when listed in alphabetical order. If there is no such anagram, return an empty String.

 

Definition

    
Class:AnagramList
Method:getAnagram
Parameters:String, int
Returns:String
Method signature:String getAnagram(String s, int i)
(be sure your method is public)
    
 

Constraints

-s will contain between 1 and 20 characters, inclusive.
-Each character of s will be a lowercase letter ('a'-'z').
-i will be between 0 and 2000000000 (2*109), inclusive.
 

Examples

0)
    
"tree"
1
Returns: "eetr"
An example from the problem statement.
1)
    
"tree"
6
Returns: "reet"
Another example from the problem statement.
2)
    
"tree"
12
Returns: ""
As you can see in the problem statement, the list of anagrams of "tree" only has 12 elements, so none of them has index 12.
3)
    
"abcabfebda"
5000
Returns: "aadfcabbbe"
4)
    
"sdoijgfasdkhaiw"
2000000000
Returns: "adsdghwiiokfjas"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7407

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10661&pm=7407

Writer:

soul-net

Testers:

PabloGilberto , brett1479 , Olexiy , Andrew_Lazarev

Problem categories:

Math, Recursion