Find number of candidates in the Exam
Last Updated :
13 Mar, 2023
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++
#include <iostream>
using namespace std;
int findParticipants( int L, int T)
{
return (L + T - 1);
}
int main()
{
int L = 10, T = 2;
cout << findParticipants(L, T);
return 0;
}
|
Java
class GFG
{
static int findParticipants( int L, int T)
{
return (L + T - 1 );
}
public static void main(String args[])
{
int L = 10 , T = 2 ;
System.out.print(findParticipants(L, T));
}
}
|
Python3
def findParticipants(L, T) :
return (L + T - 1 );
if __name__ = = "__main__" :
L = 10 ; T = 2 ;
print (findParticipants(L, T));
|
C#
using System;
class GFG
{
static int findParticipants( int L, int T)
{
return (L + T - 1);
}
public static void Main()
{
int L = 10, T = 2;
Console.Write(findParticipants(L, T));
}
}
|
Javascript
<script>
function findParticipants(L, T)
{
return (L + T - 1);
}
var L = 10, T = 2;
document.write( findParticipants(L, T));
</script>
|
Time complexity: O(1) as constant operations are being performed
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...