Dropbox Interview Question
Software EngineersCountry: United States
Interview Type: In-Person
Given the query (x, y), we will know in O(1) if there is any light in the horizontal line that passes (0, y) and if there is any light in the vertical line that passes (x, 0).
Basically, we keep two hash sets:
one that has x coordinates where there is at least one light above or below
one that has y coordinates where there is at least one light on the right or left
This might not work intuitively when we see if there is any light in any diagonal direction.. but looks like there's a trick.
We can diagonally project all the rights to the X axis, and use the x coordinate as the key. There are two "diagonal" directions, so we would have two more hash sets.
For each query (x, y), we can simply check if this belongs to any of the four hash sets.
x in S(X)?
y in S(Y)?
x - y in S(Diagonal 1st)?
x + y in S(Diagonal 2nd)?
If anything is true, then it has light. If not, it doesn't.
Looking for interview experience sharing and coaching?
Visit AONECODE.COM for ONE-TO-ONE private lessons by FB, Google and Uber engineers!
SYSTEM DESIGN Courses (highly recommended for candidates of FB, LinkedIn, Amazon, Google & Uber etc.)
ALGORITHMS (conquer DP, Greedy, Graph, Advanced Algorithms & Clean Coding),
latest interview questions sorted by companies,
mock interviews.
Our students got hired from G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.
Email us aonecoding@gmail.com with any questions. Thanks!
SOLUTION
- aonecoding March 21, 2018