A short summary of problems with strings and arrays

This is just a short summary of what I have learned from the previous problems.

  1.  If you are dealing with Java Strings, converting it to character array might be helpful.
  2. Ask about the type of characters in the string. Are they ASCII characters?
  3. Sometimes you will count the frequency of the characters in the string, so ask the second question is important. If they are all ASCII characters, you can just use an array of size 256.
  4. If you are not allowed to use additional data structures doing string manipulation, think about bit manipulation. The bit format provides you more stuff to work on. You may also want to consider using two index variables to keep track of the character’s position.
  5. Two ways to exam characters in a string: from the current position and look into the latter parts of the string; or from the current position and look back into the previous parts of the string (which you can keep track of, e.g., character frequency).
  6. If you are dealing with expanding, consider starting from the end of the string. Otherwise, start from the beginning of the string.
  7. If the question gives you something (for example, a known function) and you can’t relate it to the question directly, try apply the function simply on the data that are given. See how far the result of that is from the expectation.
Enhanced by Zemanta