- 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?
- 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 count number of ways we can throw n dices in Python
- Program to find number of good ways to split a string using Python
- Program to find number of ways we can decode a message in Python
- Program to find number of ways we can split a palindrome in python
- How to position Tkinter widgets so that they are not stuck together?
- Program to find higher number with same number of set bits as n in Python?\n
- Number of Ways to Paint N × 3 Grid in C++ program
- C++ Program to Generate N Number of Passwords of Length M Each
- Program to find number of ways we can concatenate words to make palindromes in Python

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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 −

import math class Solution: def solve(self, n): return math.factorial(n) ob = Solution() print(ob.solve(3))

3

6

Advertisements