How to do run length encoding?

Posted by Phoenix on Stack Overflow See other posts from Stack Overflow or by Phoenix
Published on 2010-03-09T01:15:03Z Indexed on 2010/03/09 1:21 UTC
Read the original article Hit count: 291

I have a long string for example it could be "aaaaaabbccc". Need to represent it as "a6b2c3". What's the best way to do this ? I could do this in linear time by comparing characters and incrementing counts and then replacing the counts in the array, using two indexes in one pass. Can you guys think of a better way than this? Are any of the encoding techniques going to work here ?

© Stack Overflow or respective owner

Related posts about interview-questions

Related posts about run-length