813. Count Arrangements of N Bishops on M×M Board

HardRecursionRecursion

Given an integer m (board size), return the maximum number of non-attacking bishops that can be placed on an m×m chessboard. Bishops attack diagonally. The answer is max(0, 2*m - 2) for m >= 2, 1 for m=1, 0 for m<=0.

Input: A single integer m.

Output: Integer.

Examples

Example 1
Input: 4
Output: 6
Explanation: 2*4-2=6 bishops.
Example 2
Input: 1
Output: 1
Explanation: One bishop on 1×1.
Example 3
Input: 0
Output: 0
Explanation: No board.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →