| 14 | import static java.util.stream.Collectors.toList; |
| 15 | |
| 16 | class 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 | |
| 47 | public class Solution { |
| 48 | public static void main(String[] args) throws IOException { |
nothing calls this directly
no outgoing calls
no test coverage detected