solution to minDepth