This question was asked in Flipkart's 2020 offcampus new grad 2021 SDE1, India hiring. The contest which was hosted on AMCAT platform had a total of three questions. The first 2 were relatively easy and involved concepts like hashing and sorting. This was one question I couldn't solve.
Question




Any suggestions on how to solve this would be welcome!
Edit-1
For people asking how I got this opportunity, Flipkart every year conducts a team based hackathon(this year everything was virtual). It's called flipkart GRID challenge. Every team that reaches the 3rd round, is given a chance to apply for full time sde roles as well as internships at flipkart while they are in college. This is the link for this year's challenge- https://dare2compete.com/o/flipkart-grid-20-software-development-challenge-flipkart-grid-20-flipkart-113664