I was asked this question recently on uber online assessment.
First task is easy. a) get a keyset b) for every key in key set, increment its value
Second task is not so trivial.
For every key, keep checking if there is key which is equal to key +1 and keep going until there is no key which is equal to key + 1. increment all the keys in reverse order.
I would like to know if there is an efficient way to implement 2.