Adobe Interview Question
Software Engineer / Developersinteger is 2/4 bytes. therefore it takes a constant steps. Does it fits the definition of O(1) ?
google MIT HAKMEM. But I wonder why adobe keeps asking these types of questions!It can never test the intelligence. If a person knows it he will tell it, or he wont able to tell it. If one can design this algo in half an hour he probably shouldnt be at adobe ;)
To be very frank I dont know the answer, but what I know is Java has Integer class which has a method bitcount which does the same thing in O(1).
- Anonymous March 17, 2011This is the extract from the Java source code
i = i - ((i >>> 1) & 0x55555555);
1085 i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
1086 i = (i + (i >>> 4)) & 0x0f0f0f0f;
1087 i = i + (i >>> 8);
1088 i = i + (i >>> 16);
1089 return i & 0x3f;
Can someone please explain the logic?