leetcode candy solution

leetcode candy solution

There are N children standing in a line. Each child is assigned a rating value.

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 get more candies than their neighbors.
What is the minimum candies you must give?

leetcode candy solution

[[code]]czo5MjM6XCINCmludCBjYW5keSh2ZWN0b3ImbHQ7aW50Jmd0OyAmYW1wO3JhdGluZ3MpIHsNCmludCAqYXJyPShpbnQqKSBtYWxsb2N7WyYqJl19KHJhdGluZ3Muc2l6ZSgpKiBzaXplb2YoaW50KSk7DQpmb3IoaW50IGk9MCA7IGkmbHQ7cmF0aW5ncy5zaXplKCk7aSsrKQ0Kew0KYXtbJiomXX1ycltpXT0xOw0KfQ0KaWYocmF0aW5nc1swXSAmZ3Q7IHJhdGluZ3NbMV0gKQ0KYXJyWzBdKz0xOw0KZm9yKGludCBpPTEgOyBpJmx0e1smKiZdfTtyYXRpbmdzLnNpemUoKS0xO2krKykNCnsNCmlmKHJhdGluZ3NbaV0gJmd0OyByYXRpbmdzW2ktMV0gJmFtcDsmYW1wOyBhcnJbaV17WyYqJl19ICZsdDs9YXJyW2ktMV0pDQphcnJbaV09YXJyW2ktMV0rMTsNCmlmKHJhdGluZ3NbaV0gJmd0OyByYXRpbmdzW2krMV0gJmFtcDsmYXtbJiomXX1tcDsgYXJyW2ldICZsdDs9YXJyW2krMV0pDQphcnJbaV09YXJyW2krMV0rMTsNCn0NCmlmKHJhdGluZ3NbcmF0aW5ncy5zaXplKCkte1smKiZdfTFdICZndDsgcmF0aW5nc1tyYXRpbmdzLnNpemUoKS0yXSApDQphcnJbcmF0aW5ncy5zaXplKCktMV09YXJyW3JhdGluZ3Muc2l6ZSh7WyYqJl19KS0yXSsxOw0KZm9yKGludCBpPXJhdGluZ3Muc2l6ZSgpLTIgOyBpJmd0OzA7aS0tKQ0Kew0KaWYocmF0aW5nc1tpXSAmZ3Q7IHJhdHtbJiomXX1pbmdzW2ktMV0gJmFtcDsmYW1wOyBhcnJbaV0gJmx0Oz1hcnJbaS0xXSkNCmFycltpXT1hcnJbaS0xXSsxOw0KaWYocmF0aW5nc1tpe1smKiZdfV0gJmd0OyByYXRpbmdzW2krMV0gJmFtcDsmYW1wOyBhcnJbaV0gJmx0Oz1hcnJbaSsxXSkNCmFycltpXT1hcnJbaSsxXSsxOw0KfQ17WyYqJl19CmlmKHJhdGluZ3NbMF0gJmd0OyByYXRpbmdzWzFdICZhbXA7JmFtcDsgYXJyWzBdICZsdDs9IGFyclsxXSkNCmFyclswXT1hcnJbMXtbJiomXX1dKzE7DQppbnQgc3VtPTA7DQpmb3IoaW50IGk9MCA7IGkmbHQ7cmF0aW5ncy5zaXplKCk7aSsrKQ0Kew0Kc3VtKz1hcnJbaV07DQp9e1smKiZdfQ0KcmV0dXJuIHN1bTsNCn0NClwiO3tbJiomXX0=[[/code]]

Resolving technical problems:

Solve your technical problems instantly

We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM

Mail your problem details at writeulearn@gmail.com along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.

One thought on “leetcode candy solution”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.