Pergunta de entrevista da empresa TikTok

Leetcode question, I believe it's Queens puzzle