Wise Interview Question

OOP/data structures problem in HackerRank