Single-sided NMR instruments utilize inhomogeneous magnetic fields with strong gradients to nondestructively probe physical properties of materials. The sensitive region of this type of magnet is often a thin slice above the magnet's surface; measuring planar samples with high spatial resolution requires coplanarity between the sensitive region of the magnet and the sample region of interest. We developed an algorithmic approach to position flat samples coplanar with the magnet's sensitive region. The efficient and objective positioning process utilizes an adjustable stage that offers control over three degrees of freedom, and the optimal position for each sample is found with a quadtree algorithm. We show this algorithm is effective for positioning samples with various relaxation behaviors. We report resolution values that describe position optimization, acquisition constraints, and final spatial resolution for each sample. Measurements after optimized positioning had appropriate spatial resolution to distinguish physical regions of layered samples with different physical properties, namely, relaxation behavior. Our algorithmic positioning process can be implemented for planar samples in research and industrial settings to enhance spatial resolution of single-sided NMR measurements.