GeeksforGeeks App
Open App
Browser
Continue

Find number of candidates in the Exam

Given the last rank ‘L’ and the number of candidates at the last rank ‘T’, the task is to find the total number of candidates in the Exam.

```Input: L = 5, T = 1
Output: 5

Input: L = 10, T = 2
Output: 11```

Approach:

1. Suppose L = 5 and T = 2.
2. Then there can be many possible rank combinations, like 1, 2, 3, 3, 5, 5.
3. So now in this, as you can see, the last rank is 5 and there are 2 students at rank 5,
4. Therefore, the total number of candidates is 6.
5. This can be understood by a simple formula:
`L+T-1`

Below is the implementation of the above approach.

C++

 `// C++ program to find total number of candidates``// in an Exam from given last rank``// and Number of student at this last rank.`` ` `#include ``using` `namespace` `std;`` ` `// Function to find total number of``// Participants in Exam.``int` `findParticipants(``int` `L, ``int` `T)``{``    ``return` `(L + T - 1);``}`` ` `// Driver code``int` `main()``{``    ``int` `L = 10, T = 2;``    ``cout << findParticipants(L, T);`` ` `    ``return` `0;``}`

Java

 `// Java program to find total number of``// candidates in an Exam from given last rank ``// and Number of student at this last rank. ``class` `GFG ``{`` ` `    ``// Function to find total number of ``    ``// Participants in Exam.``    ``static` `int` `findParticipants(``int` `L, ``int` `T)``    ``{``        ``return` `(L + T - ``1``);``    ``}`` ` `    ``// Driver code ``    ``public` `static` `void` `main(String args[]) ``    ``{``        ``int` `L = ``10``, T = ``2``;``        ``System.out.print(findParticipants(L, T));``    ``}``}`` ` `// This code is contributed by Gowtham Yuvaraj`

Python3

 `# Python3 program to find total number ``# of candidates in an Exam from given last rank ``# and Number of student at this last rank. `` ` `# Function to find total number of ``# Participants in Exam. ``def` `findParticipants(L, T) : `` ` `    ``return` `(L ``+` `T ``-` `1``); `` ` `# Driver code ``if` `__name__ ``=``=` `"__main__"` `: `` ` `    ``L ``=` `10``; T ``=` `2``; ``    ``print``(findParticipants(L, T)); ``     ` `# This code is contributed by AnkitRai01`

C#

 `// C# program to find total number of``// candidates in an Exam from given last rank ``// and Number of student at this last rank. ``using` `System;`` ` `class` `GFG ``{`` ` `    ``// Function to find total number of ``    ``// Participants in Exam.``    ``static` `int` `findParticipants(``int` `L, ``int` `T)``    ``{``        ``return` `(L + T - 1);``    ``}`` ` `    ``// Driver code ``    ``public` `static` `void` `Main() ``    ``{``        ``int` `L = 10, T = 2;``        ``Console.Write(findParticipants(L, T));``    ``}``}`` ` `// This code is contributed by Gowtham Yuvaraj`

Javascript

 ``

Output:

`11`

Time complexity: O(1) as constant operations are being performed
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up