Important Problems on Strings and Arrays
By admin on August 13, 2016
Category:
Problem:

Write an algorithm to reverse a string.

Assumptions
 You cannot use any library functions.
 You may use charAt (if needed.)

Assumptions

Write an algorithm to find out if a string has all unique characters.

Assumptions
 You cannot use additional data structures.
 References

Assumptions

Given two strings, write an algorithm to find if one string is a permutation of the other.

Definitions
 permutation (or anagram) denote two strings that have same characters (with same numbers), but in different order.

Example
 LISTEN and SILENT (have same characters, but in different order).

Definitions

Write an algorithm for string compression using counts of repeated characters

Example
 aaaaarrrrbbb will become a5r4b3

Assumptions
 if the new compressed string is is bigger than the original string, return original string.

Example

Write an algorithm to find if one word is a substring of other.

Example:
 bcd is a substring of abcde
 def is not a substring of abcde

Assumptions
 You should not use any Java library functions such as contains, but may use charAt alone (if needed).

Example:

Using the above algorithm alone (isSubstring), find if one string is a rotation of other.

Example
 datastructures is a rotation of astructuresdat.
 cdeab is a rotation of abcde
 cdaeb is not a rotation of abcde.

Example
Solution:
Refer to individual problems under corresponding problem category for solutions.