Sort by

recency

|

1446 Discussions

|

  • + 0 comments

    This is a great problem for thinking through logic step by step. It all comes down to checking the tallest hurdle and seeing if the character, much like an extreme introvert navigating social situations, can already clear it. If not, just calculate how many extra boosts are needed. Pretty straightforward but a fun way to break down constraints.

  • + 0 comments

    import java.util.*;

    public class Solution {

    public static int hurdleRace(int k, List<Integer> height) {
        int maxHurdle = Collections.max(height);
        return Math.max(0, maxHurdle - k);
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
    
        int n = scanner.nextInt(); // number of hurdles
        int k = scanner.nextInt(); // max jump height
    
        List<Integer> height = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            height.add(scanner.nextInt());
        }
    
        int result = hurdleRace(k, height);
        System.out.println(result);
    
        scanner.close();
    }
    

    }

  • + 0 comments

    int biggestHurdle = height.Max();

    return biggestHurdle > k ? biggestHurdle - k : 0;

  • + 0 comments
    scala
        def hurdleRace(k: Int, height: Array[Int]): Int = {
      height.foldLeft(0)({case (acc, n) => max(n-k, acc)})
    }
    
  • + 0 comments

    Rust:

    (height.iter().max().unwrap() - k).max(0)