Find Close Particle Pairs in a Periodic Box Using Cells
Last updated: November 29, 2026
Quick Overview
Given N particle positions in a cubic box of side L with periodic boundaries, return all pairs closer than a cutoff rc under the minimum image convention, in roughly O(N) time for uniform density.
D. E. Shaw
November 29, 20260
0
0 solved
Given N particle positions in a cubic box of side L with periodic boundaries, return all pairs closer than a cutoff rc under the minimum image convention, in roughly O(N) time for uniform density.
Reflects the kind of scientific computing problem associated with D. E. Shaw Research, whose molecular dynamics work (Anton, Desmond) depends on fast neighbor finding. The interviewer checks spatial hashing, correct periodic wraparound, and avoidance of double counting.
What the Interviewer Expects
- Bins particles into cells of side at least rc
- Searches only the 27 neighboring cells with periodic wrap
- Applies the minimum image convention to each coordinate
- Avoids double counting with i < j and handles boxes with fewer than 3 cells per side
- States O(N) expected time at fixed density and compares with O(N^2)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you parallelize this across many cores or nodes?
- What is a Verlet list and when does rebuilding it pay off?
- How do you handle a triclinic (non cubic) periodic cell?
- How would you make results bitwise reproducible across different processor counts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: positions in , box side L, cutoff rc with (so the minimum image is unique). Output: sorted list of pairs , , with minimum image distance below rc....
High-Level Design
Split the box into ncell = floor(L / rc) cells per side, so each cell side is at least rc and any partner within rc lies in the same or an adjacent cell. Hash each particle to its cell, then for eve...