Showing posts with label Hacker Rank Solution. Show all posts
Showing posts with label Hacker Rank Solution. Show all posts

Kangaroo jump problem Solution (Hacker Rank)


Kangaroo jump problem Solution (Hacker Rank)











Problem 






Solution 

    static string kangaroo(int x1, int v1, int x2, int v2)
        {
            int kangarro1 = x1 + v1;
            int kangarro2 = x2 + v2;
                while (kangarro1 <= 10000 || kangarro2 >= 10000)
                {
                    if (kangarro1 == kangarro2)
                    {
                        return "YES";

                    }
                    kangarro1 = kangarro1 + v1;
                    kangarro2 = kangarro2 + v2;
                }

                return "NO";
        }


Share:

Grading Students - Hacker Rank Solution



At HackerLand University, a passing grade is any grade 40 points or higher on a 100 point scale. Sam is a professor at the university and likes to round each student’s grade according to the following rules:
·         If the difference between the grade and the next higher multiple of 5 is less than 3, round to the next higher multiple of 5
·         If the grade is less than 38, don’t bother as it’s still a failing grade
Automate the rounding process then round a list of grades and print the results.
Input Format
The first line contains a single integer denoting  (the number of students).
Each line  of the  subsequent lines contains a single integer, , denoting student 's grade.


 Grading Students - Hacker Rank Solution


Solution in C#

public static List<int> gradingStudents(List<int> grades) { List<int> Newgrades = new List<int>(); foreach (int item in grades) { int val = item; int next5mul = 0; int Valu1 = 0; int i = 1; while (item >= next5mul) { next5mul = i * 5; i++; } if (next5mul - item < 3) { Newgrades.Add(next5mul); } else { Newgrades.Add(item); } } return Newgrades; }







Share:

Popular

Tags

Mobile

Recent Posts