DEV Community

Discussion on: The challenge to make a shape area calculation in CodeSignal

Collapse
 
radwaalaa profile image
Radwa Alaa

this is the shortest valid solution :

int output = 1;
for (int i = 1; i <= n; i++) {
if (i != 1) {
output = output + 4 * (i - 1);
}
}

return output;
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hodasalah profile image
hodasalah

i tried both solution
function solution(n) {
return 2*n*(n-1) +1;
//return n*2+(n-1)*2
}