Arista Networks Interview Question
Team: platform engineering intern
Country: United States
Interview Type: Phone Interview
#include <iostream>
using namespace std;
int main(void){
/* find a*b */
int a = 3;
int b = 123;
int shift = 0;
int target = b;
int prod = 0;
while(target>0){
shift = 0;
while(1<<shift <= target){
shift++;
}
shift--;
prod += a<<shift;
target -= 1<<shift;
}
std::cout<< " "<<prod;
return 0;
}
Can be refined to handle negative numbers and overflow...
- david.rebatto@gmail.com March 30, 2012