Dropbox Interview Question for Software Engineers


Country: United States
Interview Type: In-Person




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

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

//O(N) time and space for processing the board and lamps
//O(1) for finding if a cell is illuminated
public class GridIllumination {

    int N; //board size
    Set<Integer> illuminated_x = new HashSet<>();
    Set<Integer> illuminated_y = new HashSet<>();
    Set<Integer> illuminated_diag0 = new HashSet();
    Set<Integer> illuminated_diag1 = new HashSet();


    //@param lamps - a list of (x,y) locations of lamps
    public GridIllumination(int N, int[][] lamps) {
        this.N = N;
        for(int[] lamp: lamps) { //this lamp illuminates 4 lines of cells
            illuminated_x.add(lamp[0]);               //the entire column
            illuminated_y.add(lamp[1]);               //the entire row
            illuminated_diag0.add(lamp[1] - lamp[0]); //diagonal line with a slope of 1
            illuminated_diag1.add(lamp[0] + lamp[1]); //diagonal lines with a slope of -1
        }
    }

    public boolean is_illuminated(int x, int y) {
        if(illuminated_x.contains(x) ||
            illuminated_y.contains(y) ||
            illuminated_diag0.contains(y - x) ||
            illuminated_diag1.contains(x + y)) {
                return true;
        }
        return false;
    }
}

- aonecoding March 21, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thanks a lot for the soln. . But why are we referring the diagonals as y-x and x+y ? Similarly adding diagonals with +1 and -1 slope, you used (lamp[1] - lamp[0]) and (lamp[0] +lamp[1]) ? I am not clear with the diagonal logic?

- trusty007 July 31, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thanks a lot for the soln. . But why are we referring the diagonals as y-x and x+y ? Similarly adding diagonals with +1 and -1 slope, you used (lamp[1] - lamp[0]) and (lamp[0] +lamp[1]) ? I am not clear with the diagonal logic?

- trusty007 July 31, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The solution is totally wrong!!!
I suggest you delete it

- obov5566 September 22, 2018 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More