Alloy interview question

One medium difficulty HackerRank question