1. Write a function (in any programming language) that gets an integer parameter and returns the number of 1 digits in its binary representation. 2. How would you implement this even faster if you had infinite memory and processing capabilities.
Anonymous
1. using namespace std; int countOnes(int n) { int ret = 0; while (n > 0) { ret += (n & 1); n >>= 1; } return ret; } 2. Store the answer in a table for all integers and look it up from there.
Check out your Company Bowl for anonymous work chats.