Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Solution: Candy
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statment

You are given ratings array of integers where ratings[i] is rating value assigned to the i<sup>th</sup> child. You are giving candies to these n children who are standing in single row.

Follow below rules to give candies to each child:

  • Each child must have at least one candy.
  • Children with a higher rating get more candies than their neighbors.

Return the minimum count of candies you require to distribute candies to the children.

Examples

  • Example 1:
    • Input: ratings = [4, 2, 3, 4]
    • Expected Output: 8

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible