// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
//counter for Se
int se=0;
//counter for w
long long int s = 0;
//loop
for(int i = 0; i < A.size();i++ )
{
//if element =0 se++
if(A[i]==0){se++;}
//if element =1 add both se and s and this gives us passing cars(how many se go with s)
if(A[i]==1){s=s+se;}
}
//edge case
if(s>1000000000){return -1;}
return s;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter