## Riot Gaming Interview Question for Software Engineers

• 1
of 1 vote

Team: unknown
Country: United States
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
1
of 1 vote

Looking for coaching on interview preparation?
Visit AONECODE.COM for ONE-TO-ONE private lessons by FB, Google and Uber engineers!

System Design (for candidates of FB, LinkedIn, AMZ, Google and Uber etc)
Algorithms (DP, Greedy, Graph etc. advanced algorithms and clean coding)
Interview questions sorted by companies
Mock Interviews

Ace G, U, FB, Amazon, LinkedIn, MS and other top-tier interviews in weeks of training.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

``````public static int divide(int dividend, int divisor) {
//if(divisor == 0) throw new Exception();
int sign = 1;
//figure out the sign of the result
if((dividend < 0 && divisor > 0)
|| (dividend > 0 && divisor < 0)) {
sign = -1;
}
if(dividend < 0) dividend = -dividend;
if(divisor < 0) divisor = -divisor;
int n = 1; //get the range of result [n, 2n], where n is doubled every round
while(dividend > (n << 1) * divisor) {
n <<= 1;
}
//now it's known that the result is between [n, 2n]
//so in the dividend has a sum of more than n and less than 2n divisors in total
//to figure out exactly how many divisors sum up to the dividend,
// break down the problem to result = n + divide(dividend - n * divisor, divisor)
// next round the dividend becomes (dividend - n * divisor) with n added to the result.
// proceed to figure out the range [x, 2x] of result for the new dividend, where x can be n/2, n/4, n/8...
// whenever the x is found, add x to the result and deduce x * divisor from the dividend
// util n is 0 or dividend is 0

//If written in math, the formula looks like dividend = ([T/F]* n + [T/F]* n/2 + [T/F]* n/ 4 + [T/F]* n/ 8...) * divisor
//The quotient will be ([T/F]* n + [T/F]* n/2 + [T/F]* n/ 4 + [T/F]* n/ 8...), [T/F] depends on (dividend - n * divisor) >= 0
int result = 0;
while(n > 0 && dividend > 0) {
if(dividend - n * divisor >= 0) {
dividend -= n * divisor;
result += n;
}
n >>= 1;
}
return result * sign;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````1 // This is the text editor interface.
2 // Anything you type or change here will be seen by the other person in real time.
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <assert.h>
7
8 int divide(int num, int div)
9 {
10     int result = 0;
11     int multiplier = 1;
12     int divMultiplier = 1;
13
14     if (num < 0)
15         multiplier = -1;
16
17     int absNum = num * multiplier;
18
19     if (div < 0)
20         divMultiplier = -1;
21
22     int absDiv = div * divMultiplier;
23
24     int lb = 0;
25     int ub = absNum + 1;
26
27     for (;;)
28     {
29         int middle = lb + ((ub - lb) >> 1);
30         int guessed = middle * absDiv;
31
32         int match = guessed == absNum || ((guessed < absNum) && (absNum - guessed) < absDiv);
33         if (match)
34         {
35             result = middle;
36             break;
37         }
38         else if (guessed < absNum)
39         {
40             lb = middle;
41         }
42         else
43         {
44             ub = middle;
45         }
46     }
47
48     result *= multiplier;
49     result *= divMultiplier;
50     return result;
51 }
52
53
54 int main(int agrc, char* argv[])
55 {
56     printf("-5 / 1 = %d\n", divide(-5,1));
57     printf("10 / 9 = %d\n", divide(10,9));
58     printf("-10 / 2 = %d\n", divide(-10,2));
59     printf("-10 / 3 = %d\n", divide(-10,3));
60     // printf("-5 / 0 = %d", divide(-5,0));
61     printf("5 / -1 = %d\n", divide(5,-1));
62     printf("10 / -11 = %d\n", divide(10,-11));
63     printf("10 / -12 = %d\n", divide(10,-12));
64     printf("10 / -21 = %d\n", divide(10,-21));
65     printf("10 / -10 = %d\n", divide(10,-10));
66     printf("0 / -1 = %d\n", divide(0,-1));
67     printf("1 / 1 = %d\n", divide(1,1));
68     printf("1 / 2 = %d\n", divide(1,2));
69     printf("100 / 101 = %d\n", divide(100,101));
70     printf("1000 / 1001 = %d\n", divide(1000,1001));
71     printf("10000 / 10001 = %d\n", divide(10000,10001));
72     printf("10001 / 10000 = %d\n", divide(10001,10000));
73     printf("10001 / 9999 = %d\n", divide(10001,9999));
74     return 0;
75 }
76``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.