InterviewLegend

Grids & Simulation

Alex Chen32 min readUpdated

Square's coding problems include a lot of simulation, and most of it happens on a grid. A ball rolls through a maze until a wall stops it. A robot walks the edge of a rectangle and turns at each corner, or a box tips onto its side and every loose stone falls until something holds it. None of these has a payments story. Each is a process you could run by hand on a small board, and interviewers reward code that runs it the same way.

The six problems come in two kinds. Some are searches with an unusual move, where BFS stays ordinary and only the meaning of one step changes. The rest are simulations whose simple loop is correct but too slow, so the work is index math that replaces the loop. An offset modulo the perimeter replaces walking lap by lap, and a hash keyed on block corners replaces a scan over ten billion blocks. These build on the one-cell-at-a-time grid BFS from Graphs & Trees.

The Block angle
Block scores running code ahead of fast code, and a simulation makes that order easy to follow. Write the literal version first. Roll the ball one cell at a time, step the robot one square, drop each stone in turn, and check the result against a three-by-three board you can trace by hand. Once it passes, the usual next step is a second part that raises the scale, like a robot told to take a hundred thousand steps or a grid too large to allocate. The literal loop then becomes the reference you test the fast version against. Without it, you're debugging the fast version blind.

BlockPremium lesson · Coding round

The 6 Block problems are below.

  1. A Premium questionCoding · Medium
  2. A Premium questionCoding · Medium
  3. A Premium questionCoding · Medium

+ 3 more in this lesson

Each with hints, the follow-up and a tested solution.

Get the Block questions

$49 a year · all 100 companies · cancel anytime

From 20,000+ candidate reports, forum threads behind logins and write-ups in Chinese.

Had your Block interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Block interview guide

Know what Block asks before you walk in.

30 coding · 5 system design · 14 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.