MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Result

Class Result

Hackerrank_problems/counting_valleys/Solution.java:16–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14import static java.util.stream.Collectors.toList;
15
16class Result {
17
18 /*
19 * Complete the 'countingValleys' function below.
20 *
21 * The function is expected to return an INTEGER.
22 * The function accepts following parameters:
23 * 1. INTEGER steps
24 * 2. STRING path
25 */
26
27 public static int countingValleys(int steps, String path) {
28 int elevation = 0;
29 int valleys = 0;
30
31 for (int i = 0; i < steps; i++) {
32 if (path.charAt(i) == 'U') {
33 if (elevation == -1) {
34 valleys ++;
35 }
36 elevation ++;
37 } else {
38 elevation --;
39 }
40 }
41 return valleys;
42
43 }
44
45}
46
47public class Solution {
48 public static void main(String[] args) throws IOException {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected