티스토리 뷰

Algorithms

The Hurdle Race

seoca 2020. 9. 25. 21:59

 

Solution in Javascript

const k = 4;
const height = [1, 6, 3, 5, 2];

function hurdleRace(k, height) {
    const max = Math.max(...height);

    if ((max - k) <= 0){
        console.log(0);
    }else{
        console.log(max - k);
    }
}

hurdleRace(k, height); 

 

 

 

 

Reference

www.hackerrank.com/challenges/the-hurdle-race/problem

 

The Hurdle Race | HackerRank

Determine the maximum value in an array less a value, limit >= 0.

www.hackerrank.com

 

'Algorithms' 카테고리의 다른 글

Utopian Tree  (0) 2020.10.01
Electronics Shop  (0) 2020.09.25
Cats and a Mouse  (0) 2020.09.17
Find Digits  (0) 2020.09.13
Bon Appétit  (0) 2020.09.12