C++ from the left & from the right & max of both
iterate from the left to right\niterate from right to left\nadd max of left pass and right pass at each index\n\nSOLVED LIVE ON TWITCH.   Everyday 6pm PT.  Link
iterate from the left to right\niterate from right to left\nadd max of left pass and right pass at each index\n\n**SOLVED LIVE ON TWITCH.   Everyday 6pm PT.  Link in profile.**\n\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int n = ratings.size();\n        \n        vector<int> lefts(n, 1);\n        vector<int> rights(n, 1);\n        \n        for(int i = 1; i < n; i++) {\n            if(ratings[i] > ratings[i-1]) {\n                lefts[i] = lefts[i-1] + 1;\n            }\n        }\n        \n        for(int i = n - 2; i >= 0; i--) {\n            if(ratings[i] > ratings[i+1]) {\n                rights[i] = rights[i+1] + 1;\n            }\n        }\n        \n        int ans = 0;\n        \n        for(int i = 0 ; i < n; i++) {\n            ans += max(lefts[i], rights[i]);\n        }\n        \n        return ans;\n        \n    }\n};\n```\n
[]