6 Lines of C++ code! too easy to believe


#1
#include <bits/stdc++.h> 
int Solution::candy(vector<int> &A) {
    vector<int> c(A.size(), 1);
    for(int i=1;i <A.size() ;i++)if(A[i]>A[i-1])c[i] = 1+c[i-1];
    for(int i =A.size() -2; i>=0; i--)if(A[i]>A[i+1])c[i] = max(c[i], 1+c[i+1]);
    return accumulate(c.begin(), c.end(), 0);}

#2

If you think that cramming your code forcefully into 6 lines makes you look smarter, you are a fool. It’s more important that your code has good readibility.


#3