TikTok Interview Question

Leetcode question, I believe it's Queens puzzle