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:
- Suppose L = 5 and T = 2.
- Then there can be many possible rank combinations, like 1, 2, 3, 3, 5, 5.
- So now in this, as you can see, the last rank is 5 and there are 2 students at rank 5,
- Therefore, the total number of candidates is 6.
- 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 <iostream> 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
<script> // Javascript 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. function findParticipants(L, T) { return (L + T - 1); } // Driver code var L = 10, T = 2; document.write( findParticipants(L, T)); </script> |
11
Time complexity: O(1) as constant operations are being performed
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!