Riot Gaming Interview Question
Software EngineersTeam: unknown
Country: United States
Interview Type: Phone Interview
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
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!
- alisonlee659 February 15, 2018