Coding Interview Club

Prepare for coding interviews in simple and structured steps

Important Problems on Strings and Arrays

  1. Write an algorithm to reverse a string.
    1. Assumptions
      1. You cannot use any library functions.
      2. You may use charAt (if needed.)
  2. Write an algorithm to find out if a string has all unique characters.
    1. Assumptions
      1. You cannot use additional data structures.
    2. References
      1. Forum topic:
  3. Given two strings, write an algorithm to find if one string is a permutation of the other.
    1. Definitions
      1. permutation (or anagram) denote two strings that have same characters (with same numbers), but in different order. 
    2. Example 
      1. LISTEN and SILENT (have same characters, but in different order).
  4. Write an algorithm for string compression using counts of repeated characters
    1. Example 
      1. aaaaarrrrbbb will become a5r4b3
    2. Assumptions
      1. if the new compressed string is is bigger than the original string, return original string.
  5. Write an algorithm to find if one word is a substring of other.
    1. Example:
      1. bcd is a substring of abcde
      2. def is not a substring of abcde
    2. Assumptions
      1. You should not use any Java library functions such as contains, but may use charAt alone (if needed).
  6. Using the above algorithm alone (isSubstring), find if one string is a rotation of other.
    1. Example
      1. datastructures is a rotation of astructuresdat.
      2. cdeab is a rotation of abcde
      3. cdaeb is not a rotation of abcde.

Refer to individual problems under corresponding problem category for solutions.

Back to Top