Bloomberg Interview Question

Has Ships, leetcode hard question6