Candies Distribution Problem Statement
Prateek is a kindergarten teacher with a mission to distribute candies to students based on their performance. Each student must get at least one candy, and if two students are adjacent in the line, the one with the higher rating should receive more candies. The goal is to minimize the total candies distributed.
Task:
Given an array 'STUDENTS'
of size 'N'
representing the ratings of students, determine the minimum number of candies Prateek needs to buy to fulfill the distribution criteria.
Example:
Given students' ratings: [5, 8, 1, 5, 9, 4].
Optimal candy distribution: [1, 2, 1, 2, 3, 1].
Total candies required: 10.
Constraints:
1 <= T <= 10^2
1 <= N <= 10^4
1 <= STUDENTS[i] <= 10^5
- Time Limit: 1 sec
Input:
The first line contains an integer 'T', the number of test cases.
Each test case begins with an integer 'N', the number of students.
Followed by 'N' space-separated integers, specifying the grades of the students.
Output:
For each test case, output the minimum number of candies required.
Note:
If two students of the same grade are adjacent, they can receive the same number of candies.
Minimal candies necessary for each student is one.
Function implementation is required, no direct printing is needed.
Be the first one to answer
Add answer anonymously...
Top Oyo Rooms Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
Oyo Rooms Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app