Pergunta de entrevista da empresa Visa Inc.

Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.

Respostas da entrevista

Sigiloso

22 de fev. de 2019

Both dividend and divisor will be 32-bit signed integers. The divisor will never be 0. Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows

Sigiloso

30 de nov. de 2019

You could make a loop with the condition of (dividend >= divisor), and while that is true, continue to subtract dividend from the divisor and assign the dividend to this difference. while (dividend >= divisor) { (dividend = dividend - divisor); quotient++; } This loop will also add one to our quotient through each pass (quotient++). If our Dividend was 26 and our divisor was 8, this loop would run 3 times (quotient++ would be reached three times). This would mean our answer, our final quotient, is 3.