Python Interview with a FAANG engineer.

Counting Black Holes with Quadtree Binary Search

Watch someone solve the counting black holes with quadtree binary search problem in an interview with a FAANG engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Interview Summary

Problem type

Counting Black Holes with Quadtree Binary Search

Interview question

Given the bottom-left and top-right coordinates of a 2D region of space (with coordinate values ranging from 0 to 1,000), and a black-box helper function blackhole_present(bottom_left, top_right) that returns true if one or more black holes exist within a given sub-region, design an efficient algorithm to count the total number of black holes in the region. The challenge is that each call to the helper function is expensive, so a brute-force, cell-by-cell scan is impractical; the solution must minimize the number of calls using a divide-and-conquer, quad-search strategy.

Interview Feedback

Feedback about Distinguished Dromedary (the interviewee)

Strengths and what went well:

Areas of Improvement:

Advise for Future interviews

Interview Transcript

Ferocious Lightning:

Hello. Hi, can you hear me?

Distinguished Dromedary:

Good, how are you?

Ferocious Lightning:

Not bad. Let's proceed.

Distinguished Dromedary:

Sure, I'm a software engineer. I've been working for about 3.5 years now. I'm focusing on time management and edge cases for technical problems.

Ferocious Lightning:

Okay, let's go straight into a hard problem.

Problem Details

Given: bottom-left and top-right coordinates with black holes present. Task: Design an efficient algorithm using divide-and-conquer to count them.

Proposed Solution

  1. Base Cases:
    • Return 0 if blackhole_present returns false.
    • Return 1 if coordinates are the same.
  2. *Divide the Region into Quadrants:
    • Recursively call count_blackholes for four quadrants.
  3. Summation: Return total count from all four quadrants.

Time and Space Complexity

Final Remarks

Thank you for your feedback: Keep practicing!