The Hurdle Race - HackerRank || HackerRank The Hurdle Race Solution

Problem Name: The Hurdle Race
Judge: HackerRank
Problem link: The Hurdle Race



HackerRank The Hurdle Race Solution in C

#include <stdio.h>

int main()
{
    int n, k, i;
    scanf("%d %d", &n, &k);
    int height[n];
    for (i = 0; i < n; i++) scanf("%d", &height[i]);
    int max = height[0];
    for (i = 0; i < n; i++)
    {
        if (height[i] > max) max = height[i];
    }
    if (max - k > 0) printf("%d\n", max - k);
    else printf("0\n");

    return 0;
}


HackerRank The Hurdle Race Solution in C++/Cpp

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, i;
    cin >> n >> k;
    int height[n];
    for (i = 0; i < n; i++) cin >> height[i];
    int max = height[0];
    for (i = 0; i < n; i++)
    {
        if (height[i] > max) max = height[i];
    }
    if (max - k > 0) cout << max - k << endl;
    else cout << 0 << endl;
    return 0;
}


HackerRank The Hurdle Race Solution in Java

import java.util.Scanner;

public class The_Hurdle_Race {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n, k, i;
        n = input.nextInt();
        k = input.nextInt();
        int[] height = new int[n];
        for (i = 0; i < n; i++) height[i] = input.nextInt();
        int max = height[0];
        for (i = 0; i < n; i++) {
            if (height[i] > max) max = height[i];
        }
        System.out.println(Math.max(max - k, 0));
    }
}




Next Post Previous Post
No Comment
Add Comment
comment url