how to solve merging repeated characters together by giving input later

alt text