Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Chessboard Squares Count

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Chessboard Squares Count. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

How many squares are there on a chessboard?

Generalize the question for an n x n chessboard, counting every square size, not only the individual cells. Implement count_squares(n), which accepts a positive integer and returns the total number of axis-aligned squares.

For example, a standard 8 x 8 chessboard contains 204 squares.

Constraints

  • 1 <= n <= 10^9
  • Count only axis-aligned squares whose sides follow the board grid
  • Return the total number of squares

Function Signature

def count_squares(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output