Thursday, September 4, 2025
HomeData Modelling & AIFind number of candidates in the Exam

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 <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>


Output: 

11

 

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

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6748 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS