I'm a software engineer focused on backend development with Node.js, NestJS, MongoDB, and React. I love building clean, maintainable systems and learning how to solve real-world problems through code.
I'm a software engineer focused on backend development with Node.js, NestJS, MongoDB, and React. I love building clean, maintainable systems and learning how to solve real-world problems through code.
I think think there's an even easier solution:
I think this is more appropriate:
function shapeArea(n) {
return (1 + (n-1)*n) *2 - 1
}
Hey buddy, can you explain your solution?
Why do you think that formula ?
Did you solve it?
Yeah, that's exactly the beauty that I talk about code fights. You can learn from other solution.
I found this solution and just replaced the variables
function shapeArea(n) {
return 1 + 2 * n * (n-1)
//1 + 2 * 4 * (3) = 3*4=12*2=24+1=25
//1 + 2 * 3 * (2) = 2*3=6*2=12+1=13
//1 + 2 * 2 * (1) = 1*2=2*2=4+1=5
//1 + 2 * 1 * (0) = 0*1*=0*2=0+1=1
}