Students Marks Sum HackerRank Problem

In a class of students, each student has a certain number of marks. The students are arranged in such a way that all boys are placed in even positions and girls are placed in odd positions. The problem is to calculate the total marks of either boys or girls based on the input gender.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Students Marks Sum HackerRank Problem HackerRank solution using CodeRankGPT:

The solution iterates over the array of marks. If the index is even, it adds the mark to the boys' total, if it's odd - to the girls' total. After the loop, it checks the gender input. If it's 'b', it returns the total marks of boys, otherwise - the total marks of girls.


int marks_summation(int* marks, int number_of_students, char gender) {
    //Write your code here.
    int boys = 0, girls = 0;
    for (int i = 0; i < number_of_students; i++) {
        if (i % 2) girls += marks[i];
        else boys += marks[i];
    }
    return (gender == 'b') ? boys : girls;
}

If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform