Skip to content

Commit 1a8c46a

Browse files
hk day 1
1 parent c84d900 commit 1a8c46a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Hackerrank/HourGlassSum.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
3+
4+
def hour_glass_sum(arr):
5+
rows = cols = len(arr) - 1
6+
max_sum = -sys.maxsize
7+
8+
for i in range(rows - 1):
9+
for j in range(cols - 1):
10+
current_hour_glass_sum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][
11+
j + 1] + arr[i + 2][j + 2]
12+
13+
if current_hour_glass_sum > max_sum:
14+
max_sum = current_hour_glass_sum
15+
return max_sum

Hackerrank/ReverseArrayInplace.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def reverse_array(a):
2+
i = 0
3+
j = len(a) - 1
4+
while i <= j:
5+
a[i], a[j] = a[j], a[i]
6+
i += 1
7+
j -= 1
8+
return a
9+

0 commit comments

Comments
 (0)