MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / func

Method func

Codechef/Java/RedAlert.java:21–40  ·  view source on GitHub ↗
(int[] arr, int n, int d, int h)

Source from the content-addressed store, hash-verified

19 }
20
21 public static void func(int[] arr, int n, int d, int h) {
22 int waterLevel = 0;
23 for (int i = 0; i < n; i++) {
24 if (arr[i] > 0) {
25 waterLevel += arr[i];
26 } else if (arr[i] == 0) {
27 if (waterLevel <= d) {
28 waterLevel = 0;
29 } else {
30 waterLevel -= d;
31 }
32
33 }
34 if (waterLevel > h) {
35 System.out.println("YES");
36 return;
37 }
38 }
39 System.out.println("NO");
40 }
41}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected