super simple solution
Intuition:\nThe approach to solving this problem involves using the concept of two passes. In the first pass, we scan the ratings from left to right and assign 
# Intuition:\nThe approach to solving this problem involves using the concept of two passes. In the first pass, we scan the ratings from left to right and assign candies to each child based on the increasing ratings from left to right. In the second pass, we scan the ratings from right to left and adjust the candies assigned based on the increasing ratings from right to left. The idea is to ensure that each child gets at least one candy and children with higher ratings get more candies than their neighbors.\n\n# Algorithm:\n\nInitialize an array left of size n+1 to store the number of candies assigned to each child based on the increasing ratings from left to right. Set all elements of left to 1, as each child must have at least one candy.\nPerform the first pass (left to right) over the ratings array and update the left array as follows:\na. If the rating of the current child ratings[i] is greater than the rating of the previous child ratings[i-1], assign one more candy than the previous child to the current child (i.e., left[i] = left[i-1] + 1).\nInitialize a variable right to 1, which will be used to keep track of the candies for the second pass (right to left).\nPerform the second pass (right to left) over the ratings array and update the left array as follows:\na. If the rating of the current child ratings[i] is greater than the rating of the next child ratings[i+1], we increment the right variable by 1.\nb. We then update the number of candies for the current child by taking the maximum between the current value in the left array and the value of right. This step ensures that we consider both the left-to-right and right-to-left information while assigning candies.\nAfter both passes are completed, sum up all the elements in the left array to get the minimum number of candies needed to satisfy the requirements.\nComplexity Analysis:\n\n# Time Complexity:\n The algorithm performs two passes through the ratings array, which takes O(n) time, where n is the number of children.\n# Space Complexity:\n The algorithm uses a left array of size n+1 to store the candies assigned to each child, which takes O(n) extra space.\n# Code\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int n=ratings.size();\n      vector<int> left(n+1,1);\n      for(int i=1;i<n;i++){\n          if(ratings[i]>ratings[i-1]) left[i]=left[i-1]+1;\n      }  \n\n      int right=1;\n      for(int i=n-2;i>=0;i--){\n          if(ratings[i]>ratings[i+1]){\n            right++;\n            left[i]=max(left[i],right);\n          }else right=1;\n      }\n\n      int sum=0;\n      for(int i=0;i<n;i++){\n            sum+=left[i];\n      }\n      return sum;\n    }\n};\n```
['C++']