Implement a method to perform string compression using the counts of repeated characters. If the “compressed” string would not become smaller than the original, return the original string.

Assume that the string has only upper and lower case letters (a-z)

Example

1
2
Input:  aabcccccaaa
Output: a2b1c5a3
Continue Reading ...

Given a string1, replace all spaces with %20. Assume that the string has sufficient space at the end to hold additional characters. Also, the “true” length of the string is given. Make sure the space occupied is constant.

Example

1
2
Input:  "Mr John Smith    ", 13
Output: "Mr%20John%20Smith"
Continue Reading ...

Given two strings, write a method to decide if one is a permutation of the other.

Continue Reading ...

Implement a function void reverse(char * str) in C/C++ which reverses a null-terminated string.

Continue Reading ...

Implement an algorithm to determine if a string has all unique characters. What if you could cannot use additional data structures?

Clarification questions

  1. Do whitespace characters count as valid characters, that is if there are two spaces in the string, will the result be false?
  2. Does capitalization (or any capital letters) matter?
Continue Reading ...