For a string such as '12233322155552'
, by removing the duplicates, I can get '1235'
.
But what I want to keep is '1232152'
, only removing the consecutive duplicates.
For a string such as '12233322155552'
, by removing the duplicates, I can get '1235'
.
But what I want to keep is '1232152'
, only removing the consecutive duplicates.
Microsoft / Amazon job interview type of question: This is the pseudocode, the actual code is left as exercise.
As a more high level, try (not actually the implementation):
You can get final output as
1232152
You can use
itertools
, here is the one linerThis would be a way: