

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find number of ways to arrange n rooks so that they cannot attack each other in Python
Suppose we have a number n representing a chessboard of size n x n. We have to find the number of ways we can place n rooks, such that they cannot attack each other. Here two ways will be considered different if in one of the ways, some cell of the chessboard is occupied, and another way, the cell is not occupied. (We know that rooks can attack each other if they are either on the same row or on the same column).
So, if the input is like 3, then the output will be 6
To solve this, we will follow these steps −
f = factorial of n
return f
Let us see the following implementation to get better understanding −
Example
import math class Solution: def solve(self, n): return math.factorial(n) ob = Solution() print(ob.solve(3))
Input
3
Output
6
- Related Questions & Answers
- Program to arrange cards so that they can be revealed in ascending order in Python
- Place K-knights such that they do not attack each other in C++
- Program to find number of ways we can arrange symbols to get target in Python?
- Program to find number of ways we can arrange letters such that each prefix and suffix have more Bs than As in Python
- Number of Ways to Wear Different Hats to Each Other in C++
- C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome
- Splitting number into n parts close to each other in JavaScript
- Program to find number of islands, from where we cannot leave in Python
- Program to find number of ways we can get n R.s using Indian denominations in Python
- Program to find number of ways to split a string in Python
- Program to count number of ways we can throw n dices in Python
- Program to balance the direction string so that each direction occurred quarter times in Python
- Program to count the number of ways to distribute n number of candies in k number of bags in Python
- Program to find number m such that it has n number of 0s at end in Python
- Python program to find ways to get n rupees with given coins
Advertisements