By searching through previously asked doubts, I figured out and understood the solution to the problem. However, my concern is that I am sure that I won’t be able to think of such a solution without any help if this question is asked in an interview. Any study material or practice questions that you would suggest to master greedy problems like this?
Grand Temple More practice questions
Start attempting problems in contests. Most of the problems like Codeforces Div. 2 A, B,C and even D are solved by greedy approaches. There’s no way out except practice.