3

PROBLEM OF THE DAY : 21/12/2023 | Candy

 8 months ago
source link: https://www.geeksforgeeks.org/videos/problem-of-the-day-21122023-candy/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PROBLEM OF THE DAY : 21/12/2023

December 22, 2023 |990 Views
PROBLEM OF THE DAY : 21/12/2023 | Candy
Problem of the Day, Array, Data Structure and Algorithm
 Save  Share  2 Likes
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Arrays but also build up problem-solving skills.

In this problem, N children are standing in a line. Each child is assigned a rating value given in the integer array ratings.
You are giving candies to these children subjected to the following requirements:

Each child must have at least one candy.
Children with a higher rating than their neighbors get more candies than their neighbors.
Return the minimum number of candies you need to have to distribute.

Example :

Input:
N = 3
ratings = [1, 0, 2]
Output: 
5

Explanation: 
You can allocate to the first, second, and third child with 2, 1, 2 candies respectively.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/candy/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/9474a4dc-7ac3-4ea0-9c4a-4a055bd5a145

Read More

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK