Mr D Food Interview Question

Had to solve like a hackerrank problem. So like data structures based.