Simple javascript solution
var candy = function(ratings) {\n        var len = ratings.length;\n        var forward = new Array(len);\n        backward = new Array(len);\n\n        forward
    var candy = function(ratings) {\n        var len = ratings.length;\n        var forward = new Array(len);\n        backward = new Array(len);\n\n        forward[0] = 1;\n        backward[len-1] = 1;\n        for (var i = 1; i < len; i++) {\n            if (ratings[i] > ratings[i-1]) forward[i] = forward[i-1] + 1;\n            else forward[i] = 1;\n        }\n\n        for (var i = len - 2; i >= 0; i--) {\n            if (ratings[i] > ratings[i+1]) backward[i] = backward[i+1] + 1;\n            else backward[i] = 1;\n        }\n        var sum = 0;\n        for (var i = 0; i < len; i++) {\n            sum += Math.max(forward[i], backward[i]);\n        }\n        return sum;\n    };
['JavaScript']