String Manipulation

This CodeNewbie Challenge will help you learn some of the basic problems you might see on a white board in an interview. This challenge was based on some of the white board problems we’ve seen throughout interviews. The goal here is to familiarize yourself with the types of white board challenges you might face in an interview.

The Challenge

For this challenge we will begin with an array of strings:

1
["apple", "banana", "orange", "pear", "grape"]

In this challenge you will be manipulating this array and the strings within it.

Level 1

In the first level you will start by reversing the order of the strings in the array. Your output should look as follows:

1
2
3
4
5
grape
pear
orange
banana
apple

Level 2

The second level starts with reversals in mind but instead of reversing the list you are now to reverse the strings themselves. Your output will look as follows:

1
2
3
4
5
elppa
ananab
egnaro
raep
eparg

Next you will take a user input string and reverse it. The input should look like:

1
Input a string to reverse:

With user input:

1
Input a string to reverse: antidisestablishmentarianism

And your output will look as follows:

1
msinairatnemhsilbatsesiditna

Level 3

The third level takes a user input and reverses it to determine if it is a palindrome or a word or phrase that is the same forward as backward. Your input screen will look as follows:

1
2
Palindrome Check:
Enter a word or phrase:

If the user enters the word “aibohphobia” your output will be as follows:

1
aibohphobia is a palindrome

If the user enters the phrase “Are we not drawn onward to new era” your output will be as follows:

1
Are we not drawn onward to new era is a palindrome

If the user enters the word banana your output will be as follows:

1
banana is not a palindrome

Hint:

You’ll need to remove the punctuation on phrases.

A step further

Going a step further with string manipulation try taking two strings and checking to see if they are anagrams (words or phrases with the same characters but in a different order). Your output should state the two strings and if they are or are not anagrams.

1
2
3
Torchwood and Doctor Who are anagrams
bicycle and acyclic are not anagrams

Hint

An easy way to do this is to check character count for each string. If they match they are anagrams.