- 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 the number of possible position in a line in Python

Suppose we have a number n, and p and q. Now suppose we are standing in a line of n people. We do not know which position we are in, but we know there are at least p people in front of us and at most q people behind us. We have to find the number of possible positions we could be in.

So, if the input is like n = 10, p = 3, q = 4, then the output will be 5, as there are 10 people and at least 3 are in front and at most 4 are at behind. So we can stand at indexes [0, 1, 2, 3, 4]. For example, at index 0, 9 people are in front, 0 are behind.

The solution is simple, we will return the minimum of q+1 and n-p

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, n, p, q): return min(q+1, n-p) ob = Solution() print(ob.solve(n = 10, p = 2, q = 5))

## Input

10, 2, 5

## Output

6

- Related Questions & Answers
- Program to find number of possible position in n-person line with few person at front and back in Python
- Program to find position of first event number of line l of a triangle of numbers in Python
- Program to Find Out the Number of Moves to Reach the Finish Line in Python
- Program to find minimum number of hops required to reach end position in Python
- Program to find number of sets of k-non-overlapping line segments in Python
- Program to find number of possible moves to start the game to win by the starter in Python
- Program to find out the minimum number of moves for a chess piece to reach every position in Python
- Program to count number of possible humble matrices in Python
- Program to find out the position of a ball after n reversals in Python
- Program to find maximum possible population of all the cities in python
- Program to find out the number of integral coordinates on a straight line between two points in Python
- Program to find length of longest possible stick in Python?
- Program to find possible number of palindromes we can make by trimming string in Python
- Program to find the mid-point of a line in C++
- Program to find slope of a line in C++

Advertisements