# Jump in rank of a student after updating marks

Given three arrays **names[]**, **marks[]** and **updates[]** where:

**names[]**contains the names of students.**marks[]**contains the marks of the same students.**updates[]**contains the integers by which the marks of these students are to be updated.

The task is find the name of the student with maximum marks after updation and the jump in the student’s rank i.e. **previous rank – current rank**.

**Note:** The details of the students are in descending order of their marks and if more than two students scored equal marks (also the highest) then choose the one who had a lower rank previously.

**Examples:**

Input:names[] = {“sam”, “ram”, “geek”, “sonu”},

marks[] = {99, 75, 70, 60},

updates[] = {-10, 5, 9, 39}

Output:Name: sonu, Jump: 3

Updated marks are {89, 80, 79, 99}, its clear that sonu has the highest marks with jump of 3

Input:names[] = {“sam”, “ram”, “geek”},

marks[] = {80, 79, 75},

updates[] = {0, 5, -9}

Output:Name: ram, Jump: 1

**Approach:** Create a structure **struct Student** to store the information of each student, each of which will have 3 attributes **name** of the student, **marks** of the student, ** prev_rank** of the student.

Now, updated the marks according to the content of the **updates[]** then with a single traversal of the array, find the student who has the highest marks after updation.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Structure to store the information of ` `// students ` `struct` `Student { ` ` ` `string name; ` ` ` `int` `marks = 0; ` ` ` `int` `prev_rank = 0; ` `}; ` ` ` `// Function to print the name of student who ` `// stood first after updation in rank ` `void` `nameRank(string names[], ` `int` `marks[], ` ` ` `int` `updates[], ` `int` `n) ` `{ ` ` ` `// Array of students ` ` ` `Student x[n]; ` ` ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` ` ` `// Store the name of the student ` ` ` `x[i].name = names[i]; ` ` ` ` ` `// Update the marks of the student ` ` ` `x[i].marks = marks[i] + updates[i]; ` ` ` ` ` `// Store the current rank of the student ` ` ` `x[i].prev_rank = i + 1; ` ` ` `} ` ` ` ` ` `Student highest = x[0]; ` ` ` `for` `(` `int` `j = 1; j < n; j++) { ` ` ` `if` `(x[j].marks >= highest.marks) ` ` ` `highest = x[j]; ` ` ` `} ` ` ` ` ` `// Print the name and jump in rank ` ` ` `cout << ` `"Name: "` `<< highest.name ` ` ` `<< ` `", Jump: "` ` ` `<< ` `abs` `(highest.prev_rank - 1) ` ` ` `<< endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// Names of the students ` ` ` `string names[] = { ` `"sam"` `, ` `"ram"` `, ` `"geek"` `}; ` ` ` ` ` `// Marks of the students ` ` ` `int` `marks[] = { 80, 79, 75 }; ` ` ` ` ` `// Updates that are to be done ` ` ` `int` `updates[] = { 0, 5, -9 }; ` ` ` ` ` `// Number of students ` ` ` `int` `n = ` `sizeof` `(marks) / ` `sizeof` `(marks[0]); ` ` ` ` ` `nameRank(names, marks, updates, n); ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to prthe name of student who ` `# stood first after updation in rank ` `def` `nameRank(names, marks, updates, n): ` ` ` ` ` `# Array of students ` ` ` `x ` `=` `[[` `0` `for` `j ` `in` `range` `(` `3` `)] ` `for` `i ` `in` `range` `(n)] ` ` ` `for` `i ` `in` `range` `(n): ` ` ` ` ` `# Store the name of the student ` ` ` `x[i][` `0` `] ` `=` `names[i] ` ` ` ` ` `# Update the marks of the student ` ` ` `x[i][` `1` `]` `=` `marks[i] ` `+` `updates[i] ` ` ` ` ` `# Store the current rank of the student ` ` ` `x[i][` `2` `] ` `=` `i ` `+` `1` ` ` ` ` `highest ` `=` `x[` `0` `] ` ` ` `for` `j ` `in` `range` `(` `1` `, n): ` ` ` `if` `(x[j][` `1` `] >` `=` `highest[` `1` `]): ` ` ` `highest ` `=` `x[j] ` ` ` ` ` `# Print the name and jump in rank ` ` ` `print` `(` `"Name: "` `, highest[` `0` `], ` `", Jump: "` `, ` ` ` `abs` `(highest[` `2` `] ` `-` `1` `), sep` `=` `"") ` ` ` `# Driver code ` ` ` `# Names of the students ` `names` `=` `[` `"sam"` `, ` `"ram"` `, ` `"geek"` `] ` ` ` `# Marks of the students ` `marks ` `=` `[` `80` `, ` `79` `, ` `75` `] ` ` ` `# Updates that are to be done ` `updates ` `=` `[` `0` `, ` `5` `, ` `-` `9` `] ` ` ` `# Number of students ` `n ` `=` `len` `(marks) ` ` ` `nameRank(names, marks, updates, n) ` ` ` `# This code is contributed by SHUBHAMSINGH10 ` |

*chevron_right*

*filter_none*

**Output:**

Name: ram, Jump: 1

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- Find the total marks obtained according to given marking scheme
- Jump Search
- Jump Pointer Algorithm
- Number of cyclic elements in an array where we can jump according to value
- Count number of ways to jump to reach end
- C program to store Student records as Structures and Sort them by Name
- Rank of all elements in an array
- Rank of an element in a stream
- Rank of all elements in a Stream in descending order when they arrive
- Find the minimum of maximum length of a jump required to reach the last island in exactly k jumps
- Minimum cost to reach end of array array when a maximum jump of K index is allowed
- Check if a graph is Strongly, Unilaterally or Weakly connected
- Maximum cost path in an Undirected Graph such that no edge is visited twice in a row
- Reverse a subarray of the given array to minimize the sum of elements at even position

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.