-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-CountingValleys.cs
45 lines (42 loc) · 1.15 KB
/
03-CountingValleys.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Text;
namespace HackerRank
{
public class CountingValleys_Result
{
public static int CountingValleys(int steps, string path)
{
char[] ch = path.ToCharArray();
int altitude = 0, valleyCount = 0;
for (int i = 0; i < ch.Length; i++)
{
if ( ch[i].ToString().ToUpper() == "U")
{
altitude++;
if (altitude == 0)
valleyCount++;
}
else
{
altitude--;
}
}
return valleyCount;
}
}
public class CountingValleys_Solution
{
public static void CountingValleys()
{
//TestCase-1
//int steps = 8;
//string path = "UDDDUDUU";
//TestCase-2
int steps = 12;
string path = "DDUUDDUDUUUD";
int result = CountingValleys_Result.CountingValleys(steps,path);
Console.WriteLine(result);
}
}
}