Compass Interview Question

Round 1: Data Structure question, related to using Maps and Sets constructing the right output