Round-1 Implement a data structure similar to Hashmap that maps integer to integer, but with additional methods: get(key), set(key, x),:- usual as a normal hashmap, incr_value(s), incr_key(s):- they respectively increment integer value of all "values" of the keys, and all "keys" of the dictionary by the value "s" eg:- if dat_str={1:10, 4:12} and I call dat_str.incr_value(7), I get dat_str as {1:17, 4:19}. Further if I now call dat_str.incr_key(7), I get dat_str as {8:17, 11:19).
Anoniem
I wrote my answer in python. intuitively, I thought of using python dict as it's similar to requirement given in the question. For incr_value and incr_key methods, I first gave brute_force methods of O(n) TC. Then I optimized incr_value to O(1) but wasn't able to do the same for incr_key. I explained to interviewer each step of my progression which he liked, but when he asked me why I wasn't able to optimize incr_key I wasn't able to explain him properly, but said I intuitively feel that use of dict might be hampering from manipulating the keys. He ended the question, which gave me disappointment that I might have got already rejected. But he asked me if I have any questions, and I asked him regarding the question only, about how close I was and was I even doing right. He was actually happy that I asked him, and said I was very close, and was just wrong in manipulating the keys. Somehow, I got selected for the next round! Lucky, I guess :-)!!