Palantir Technology Interview Question
Software EngineersCountry: United States
Interview Type: In-Person
Javascript using bit operations:
function insertBits(n, a, b, k) {
let k_shifted = k << a; //shifing a positions will put a*0 in the front: 0b111 >> 2 = 0b11100
let filter = 0b1111111111111111111111111111111; //only 31 bits, as 1 bit is used for sign. This is the full filter.
filter = filter>>(31-b); //we put 0s to the right
console.log(decToBin(filter));
return n+(k_shifted&filter);
}
Python:
- chncyhn April 20, 2018