-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayChallenges.cs
More file actions
52 lines (43 loc) · 1.35 KB
/
ArrayChallenges.cs
File metadata and controls
52 lines (43 loc) · 1.35 KB
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
public static class ArrayChallenges
{
/*
https://www.hackerrank.com/challenges/2d-array/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays
*/
public static int hourglassSum(List<List<int>> arr)
{
var sumList = new List<int>();
int i = 0;
int j = 0;
while(i < 4)
{
var sum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] +
arr[i + 1][j+ 1] +
arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2];
sumList.Add(sum);
j++;
if(j == 4)
{
i++;
j = 0;
}
}
return sumList.Max();
}
/*
https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays
*/
public static List<int> rotLeft(List<int> a, int d)
{
var size = a.Count;
var res = new int[size];
if(size == d)
return a;
for(var i = 0; i < size; i++){
if(size + i - d >= size)
res[i - d] = a[i];
else
res[size + i - d] = a[i];
}
return res.ToList();
}
}