Raghu Go wrote:

> Example input string - abbccdaab
> desired output - 'a' = 0 6 7
> 'b' = 1 2 8
> 'c' = 3 4
> 'd' = 5

irb(main):001:0> a = "abbccdaab"
=> "abbccdaab"
irb(main):002:0> i = 0
=> 0
irb(main):003:0> ret = Hash.new
=> {}
irb(main):004:0> a.scan(/./) {|c|
irb(main):005:1*   d = [i]
irb(main):006:1>   ret[c] = ret[c].nil? ? d : d << ret[c]
irb(main):007:1>   ret[c].flatten!
irb(main):008:1>   i = i + 1
irb(main):009:1> }
=> "abbccdaab"
irb(main):010:0> p a
"abbccdaab"
=> nil
irb(main):011:0> p ret
{"a"=>[7, 6, 0], "b"=>[8, 2, 1], "c"=>[4, 3], "d"=>[5]}
=> nil
irb(main):012:0>