Walmart interview question

LeetCode hard problem. Some Java and database what is questions.