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.

AnswerBot
4mo
The task is to distribute candies to students based on their performance while minimizing the total candies distributed.
Iterate through the array of student ratings to determine the minimum number of ...read more
Help your peers!
Add answer anonymously...
Oyo Rooms Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Leaves at Same Level Problem Statement Given a binary tree with 'N' nodes, deter...read more
A Software Developer Intern was asked Q. Maximum Non-Adjacent Subsequence Sum Given an array of integers, determine the m...read more
A Software Developer Intern was asked Q. Given the employee and department tables, how would you find the number of emplo...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Leaves at Same Level Problem Statement Given a binary tree with 'N' nodes, deter...read more
A Software Developer Intern was asked Q2. Maximum Non-Adjacent Subsequence Sum Given an array of integers, determine the m...read more
A Software Developer Intern was asked Q3. Given the employee and department tables, how would you find the number of emplo...read more
>
Oyo Rooms Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

