-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-CloudsJumping.cs
82 lines (70 loc) · 2.06 KB
/
04-CloudsJumping.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HackerRank
{
public class CloudsJumping_Result
{
//public static int jumpingOnClouds(List<int> c)
//{
// int totalJumps = 0;
// int cycle = 0;
// for (int i = 0; i < c.Count - 1; i++)
// {
// if (c[i] == 0)
// {
// if (cycle + 2 <= c.Count - 1 && c[i + 2] == 0)
// {
// totalJumps++;
// i++;
// cycle = cycle + 2;
// }
// else if (c[i + 1] == 0)
// {
// totalJumps++;
// cycle++;
// }
// }
// }
// return totalJumps;
//}
public static int jumpingOnClouds(List<int> c)
{
int counter = -1;
int length = c.Count;
for (int i = 0; i < length; i++, counter++)
{
if (i + 2 < length && c[i + 2] == 0)
{
i++;
}
}
return counter;
}
}
public class CloudsJumping_Solution
{
public static void CloudsJumping()
{
//Test-1
string numbers = "0 0 0 0 1 0";
//output = 3
//Test-2
//string numbers = "0 0 1 0 0 1 0";
//output = 4
//Test-3
//string numbers = "0 1 0 0 0 1 0";
//output = 3
//Test-4
//string numbers = "0 1 0 0 0 1 1";
//output = 2
//Test-5
//string numbers = "0 0 0 1 0 0";
//output = 3
List<int> c = numbers.TrimEnd().Split(' ').ToList().Select(cTemp => Convert.ToInt32(cTemp)).ToList();
int result = CloudsJumping_Result.jumpingOnClouds(c);
Console.WriteLine(result);
}
}
}