Easily Explained ||  3 line Explanation !!!!
Intuition\nWe create 2 vectors left and right .\nIn one iteration we iterate from left and in on iteration towards right.\nIn the end we take maximum of left an
# Intuition\nWe create 2 vectors left and right .\nIn one iteration we iterate from left and in on iteration towards right.\nIn the end we take maximum of left and right.\n# Approach\n1. We maintain two arrays, left and right, to track the number of candies to be given to each child from the left and right side, respectively.\n2. We iterate through the ratings to update these arrays accordingly.\n3. Finally, we calculate the total number of candies needed by summing up the maximum of left[i] and right[i] for each child.\n\n# Complexity\n- Time complexity: \nO(n), where n is the size of the ratings vector, as we traverse the vector twice independently.\n- Space complexity:\n O(n), as we use two additional arrays of size n \n# Code\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<int> left(ratings.size() , 1);\n        vector<int> right(ratings.size() , 1);\n        int ans = 0;\n        for( int i = 1 ; i < ratings.size() ; i++ )\n        {\n            if(ratings[i-1] < ratings[i])\n            {\n                left[i] = left[i-1] +1;\n            }\n        }\n        for( int i = ratings.size()-1 ; i > 0  ; i-- )\n        {\n            if(ratings[i-1] > ratings[i])\n            {\n                right[i-1] = right[i] +1 ;\n            }\n        }\n        for( int i = 0 ; i < ratings.size() ; i++ )\n        {\n            ans = ans + max(left[i] ,right[i]);\n            \n        }\n        return ans;\n        \n        \n    }\n};\n```
['Array', 'Greedy', 'C++']