# Here your code ! def possible?(s) lines = [] s.chars.reverse.find {|c| if c == 'R' lines << 2 false elsif c == 'G' redpos = lines.find_index(2) lines[redpos] = 1 if redpos !redpos else wgpos = lines.find_index {|v| v < 2} lines[wgpos] = 0 if wgpos lines.sort if wgpos > 0 !wgpos end }.nil? end