Why You Should Love (Not Fear) “Interview Questions”

It’s funny because it’s true!

Yay, Me!

Welcome to Your Nightmare

You have 1000 bottles of soda, and exactly one is poisoned. You have 10 test strips which can be used to detect poison. A single drop of poison will turn the test strip positive permanently. You can put any number of drops on a test strip at once and you can reuse a test strip as many times as you'd like (as long as the results are negative.) However, you can only run tests once per day and it takes seven days to return a result. How would you figure out the poisoned bottle in as few days as possible?

Welcome Out of Your Nightmare

let foundBottle = false;
let poisonedBottle;
let testStrips =[];
let bottles = [];
let day = 0;
let minBottle=0;
let maxBottle=1000;
// initialize 10 test strips, all white, all ready to use
// (dayLeft:0) means days waiting for test result
// rangeMin, rangeMax are where that strip will be used
const initTestStrips = () => {for(let i=0; i<10;i++) {testStrips.push({
testStripNumber: i,
testStripColor: "white",
daysLeft: 0,
rangeMin: 0,
rangeMax: 0})
}
}
// figure up which bottle has the poison in itconst initPoison =() => {poisonedBottle = getRandomInt(1,1000);
}
// count how many test strips are not waiting for
// test results
const testStripsLeft = () => {let testStripsLeft = 0;
testStrips.forEach(testStrip => {
if(testStrip.daysLeft===0) {
testStripsLeft++;
}
})
return testStripsLeft;
}
Just do what the interviewer asks

The Real Nightmare Was the Friends We Made Along the Way!

Bonus: The Number One Character Trait of Good Programmers

4a 75 73 74 20 61 6e 6f 74 68 65 72 20 63 6f 6d 70 75 74 65 72 20 6e 65 72 64 20 77 69 74 68 20 61 20 62 6c 6f 67