
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Cell Count After Removing Corner Diagonals in Python
Suppose we have a number n representing the length of an n x n board. We have to delete all cells that are diagonal to one of the four corners and return the number of empty cells.
So, if the input is like n = 4,
X | O | O | X |
O | X | X | O |
O | X | X | O |
X | O | O | X |
Then the output will be 8.
To solve this, we will follow this formula −
- n*n - 2 * n +(n mod 2)
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, n): return n*n - 2 * n + (n%2) ob = Solution() print(ob.solve(4))
Input
4
Output
8
- Related Articles
- Find paths from corner cell to middle cell in maze in C++
- Program to count maximum score from removing substrings in Python
- Program to find string after removing consecutive duplicate characters in Python
- Program to find shortest string after removing different adjacent bits in Python
- Program to find mean of array after removing some elements in Python
- Program to find largest island after changing one water cell to land cell in Python
- Smallest number after removing n digits in JavaScript
- Balance a string after removing extra brackets in C++
- Maximum points covered after removing an Interval in C++
- Implementing Shi-Tomasi Corner Detector in OpenCV Python
- C++ code to find xth element after removing numbers
- Program to find min length of run-length encoding after removing at most k characters in Python
- Detecting corners using Harris corner detector in Python OpenCV
- Removing strings from tuple in Python
- Removing duplicates from tuple in Python

Advertisements