Interview Question: Reduced String

A reduced string is a string with all repeating letters condensed into one. The exercise was writing a function that compares two strings and returns true if their reduced string is the same.

What I did for this was…

  1. have a pointer to the start of each string
  2. compare the two letters
  1. if they’re not the same, return false
  • for each string, advance the pointer until it lands on a different character.
  • repeat steps 2-3 until null terminated.
    1. if only one was terminated and the other hasn’t, return false
  • return true
  • And that’s it. Better ideas? Corrections (I might have mistyped, it’s early)?


    Posted in No Category, Programming, Thinking Out Loud by with 2 comments.

    Comments