Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 908 Bytes

squares-in-nn-chessboard1801.md

File metadata and controls

34 lines (25 loc) · 908 Bytes

Squares in N*N Chessboard

Problem Link

Find total number of Squares in a N*N chessboard.

Calculation

image

Sample Input

2

Sample Output

5

Solution

class Solution {
  public:
    long long squaresInChessBoard(long long N) {
        
        long long ans = N * (N + 1) * (2*N + 1) / 6;
        
        return ans;
    }
};

Accepted

image