Bloomberg interview question

Has Ships, leetcode hard question6