Sie sind auf Seite 1von 3

Challenge 2: Palindromes

A palindrome is a word that reads the same backward as forward. For instance
"civic" or "deed" are palindromes while "toyota" is not.
Given a list of words
Your task is to
write a function that rearranges their letters so that they become palindromes
for example, having the sequence cecarar we can rearrange the letters and
obtain racecar which is a palindrome
print to the standard output (stdout) a single line containing one palindrome that
can be obtained from the initial word by rearranging its letters or -1 if its not
possible to obtain a palindrome (for each of the given words)
please note that the palindromes don't have to be necessarily real words from the
English dictionary (e.g. dbd is a valid palindrome word)
Note that your function will receive the following arguments:
words
which is an array of strings giving the words that need to have their letters
rearranged to obtain palindromes
Data constraints
the number of words that need to br rearranged will not exceed 1000
the maximum length of any of the words will not exceed 1000 characters
all words will contain only lowercase English letters (a-z)
Efficiency constraints
your function is expected to print the requested result and return in less than 2
seconds
Example
Input Output
words: [ivcci, oyotta, cecarar, "bbb", "babbb"]
civic
-1

racecar
bbb
bbabb

Challenge 1: N-grams
An N-gram is a sequence of N consecutive characters from a given word. For the
word "pilot" there are three 3-grams: "pil", "ilo" and "lot".
For a given set of words and an n-gram length
Your task is to
write a function that finds the n-gram that is the most frequent one among all the
words
print the result to the standard output (stdout)
if there are multiple n-grams having the same maximum frequency please print the
one that is the smallest lexicographically (the first one according to the dictionary
sorting order)
Note that your function will receive the following arguments:
text
which is a string containing words separated by whitespaces
ngramLength
which is an integer value giving the length of the n-gram
Data constraints
the length of the text string will not exceed 250,000 characters
all words are alphanumeric (they contain only English letters a-z, A-Z and numbers
0-9)
Efficiency constraints
your function is expected to print the result in less than 2 seconds
Example
Input Output

text: aaaab a0a baaab c


ngramLength: 3
aaa
Explanation
For the input presented above the 3-grams sorted by frequency are:
"aaa" with a frequency of 3
"aab" with a frequency of 2
"a0a" with a frequency of 1
"baa" with a frequency of 1