TikTok interview question

Leetcode question, I believe it's Queens puzzle