Meta Interview Question

Leetcode medium, number of neighbors