Skip to content

Commit 88e68d4

Browse files
committed
Fix linting for HackerRank solutions
1 parent 2382a47 commit 88e68d4

13 files changed

+66
-62
lines changed

HackerRank/Almost-Sorted-u.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,57 @@
22
# https://www.hackerrank.com/challenges/almost-sorted/problem
33

44
class Reverse:
5-
def __init__(self,arr):
5+
def __init__(self, arr):
66
self.arr = arr
7-
self.l,self.r = 0,0
8-
7+
self.left, self.right = 0, 0
8+
99
def canReverse(self):
1010
reverse = []
11-
for index,item in enumerate(self.arr):
11+
for index, item in enumerate(self.arr):
1212
if index != len(self.arr) - 1:
1313
if item > self.arr[index+1]:
14-
self.l = index
14+
self.left = index
1515
arr2 = self.arr[index:]
16-
for index2,item2 in enumerate(arr2):
17-
if index2 != len(arr2)-1:
16+
for index2, item2 in enumerate(arr2):
17+
if index2 != len(arr2)-1:
1818
if item2 > arr2[index2+1]:
19-
reverse.append(item2)
19+
reverse.append(item2)
2020
else:
2121
reverse.append(item2)
22-
self.r = index2
22+
self.right = index2
2323
break
2424
else:
2525
reverse.append(item2)
26-
self.r = index2
27-
break
26+
self.right = index2
27+
break
2828
break
2929
else:
3030
return False
31-
32-
self.arr[self.l,self.r] = reversed(self.arr[self.l,self.r])
33-
return self.arr == sorted(self.arr)
31+
32+
self.arr[self.left:self.right + 1] = reversed(
33+
self.arr[self.left:self.right + 1]
34+
)
35+
return self.arr == sorted(self.arr)
36+
3437

3538
class Swap:
36-
def __init__(self,arr):
39+
def __init__(self, arr):
3740
self.arr = arr
38-
self.l,self.r = 0,0
39-
41+
self.l, self.r = 0, 0
42+
4043
def canSwap(self):
41-
for index,item in enumerate(self.arr):
42-
if index != len(self.arr) -1:
44+
for index, item in enumerate(self.arr):
45+
if index != len(self.arr) - 1:
4346
if item > self.arr[index+1]:
4447
# Gave up here :D
45-
pass
48+
pass
4649
else:
4750
return False
48-
51+
4952

5053
def almostSorted(arr):
5154
if arr == sorted(arr):
5255
print("yes")
5356
else:
5457
# Checks
55-
pass
58+
pass

HackerRank/Bill-Division.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://www.hackerrank.com/challenges/bon-appetit/problem
33

44
def bonAppetit(bill, k, b):
5-
if b==sum(bill)/2:
5+
if b == sum(bill)/2:
66
bill.pop(k)
77
print(f"{b-sum(bill)//2}")
88
else:
@@ -12,4 +12,4 @@ def bonAppetit(bill, k, b):
1212
# bonAppetit([3, 10, 2, 9], 1, 12) - 5
1313
# bonAppetit([3, 10, 2, 9], 1, 7) - Bon Appetit
1414

15-
# Status - Accepted
15+
# Status - Accepted

HackerRank/Breaking-the-Records.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
33

44
def breakingRecords(scores):
5-
min_,max_ = scores[0],scores[0]
6-
ans = [0,0]
5+
min_, max_ = scores[0], scores[0]
6+
ans = [0, 0]
77
for item in scores:
88
if item > max_:
99
ans[0] += 1
@@ -17,4 +17,4 @@ def breakingRecords(scores):
1717
# breakingRecords([10,5,20,20,4,5,2,25,1]) - [2,4]
1818
# breakingRecords([3,4,21,36,10,28,35,5,24,42]) - [4,0]
1919

20-
# Status - Success
20+
# Status - Success

HackerRank/Caesar-Cipher-1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ def caesarCipher(s, k):
66
ans = ""
77
for char in s:
88
if char.upper() in alphabet:
9-
rotated = alphabet[(alphabet.index(char.upper())+k)%26]
10-
ans += rotated if char.isupper() else rotated.lower()
11-
else:
9+
rotated = alphabet[(alphabet.index(char.upper())+k) % 26]
10+
ans += rotated if char.isupper() else rotated.lower()
11+
else:
1212
ans += char
1313
return ans
1414

1515
# Testcases
1616
# "middle-Outz" 2 -> "okffng-Qwvb"
1717
# "Always-Look-on-the-Bright-Side-of-Life" 5 -> "Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj"
1818

19-
# Status - Accepted
19+
# Status - Accepted

HackerRank/Compare-Triplets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# https://www.hackerrank.com/challenges/compare-the-triplets/
33

44
def compareTriplets(a, b):
5-
ans1,ans2 = 0,0
6-
for i in range(0,3):
5+
ans1, ans2 = 0, 0
6+
for i in range(0, 3):
77
if a[i] > b[i]:
88
ans1 += 1
99
elif a[i] == b[i]:
1010
continue
1111
else:
1212
ans2 += 1
13-
return [ans1,ans2]
13+
return [ans1, ans2]
1414

1515
# Testcases
1616
# a = [5,6,7] - b = [3,6,10] - [1,1]
1717
# a = [17,28,30] - b = [99,16,8] - [2,1]
1818

19-
# Status - Passed
19+
# Status - Passed

HackerRank/Counting-Sort-1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def countingSort(arr):
1111
# Input: 63 25 73 1 98 73 56 84 86 57 16 83 8 25 81 56 9 53 98 67 99 12 83 89 80 91 39 86 76 85 74 39 25 90 59 10 94 32 44 3 89 30 27 79 46 96 27 32 18 21 92 69 81 40 40 34 68 78 24 87 42 69 23 41 78 22 6 90 99 89 50 30 20 1 43 3 70 95 33 46 44 9 69 48 33 60 65 16 82 67 61 32 21 79 75 75 13 87 70 33
1212
# Expected: 0 2 0 2 0 0 1 0 1 2 1 0 1 1 0 0 2 0 1 0 1 2 1 1 1 3 0 2 0 0 2 0 3 3 1 0 0 0 0 2 2 1 1 1 2 0 2 0 1 0 1 0 0 1 0 0 2 1 0 1 1 1 0 1 0 1 0 2 1 3 2 0 0 2 1 2 1 0 2 2 1 2 1 2 1 1 2 2 0 3 2 1 1 0 1 1 1 0 2 2
1313

14-
# Status: Accepted
14+
# Status: Accepted

HackerRank/Diagonel-Difference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://www.hackerrank.com/challenges/diagonal-difference/problem
33

44
def diagonalDifference(arr):
5-
diag1,diag2 = 0,0
5+
diag1, diag2 = 0, 0
66
for i in range(len(arr)):
77
diag1 += arr[i][i]
88
diag2 += arr[i][len(arr)-1-i]
@@ -17,7 +17,7 @@ def diagonalDifference(arr):
1717
# Status - Passed
1818

1919

20-
##Note: one of the testcase matrix was this (Answer: 462):
20+
# Note: one of the testcase matrix was this (Answer: 462):
2121

2222
# 15 49 -77 31 15 -17 -96 80 79 -11 -33 -95 -40 85 1 -84 -89 -66 81 38 26 -65 -15 -19 -29 -69 80 51 79 -42
2323
# -93 -96 22 41 -38 -36 94 96 -47 -83 -61 13 47 -25 -71 74 93 5 3 23 47 -19 6 -53 41 -48 -34 39 -55 -100
@@ -48,4 +48,4 @@ def diagonalDifference(arr):
4848
# -56 24 91 80 -56 -78 60 0 -38 -93 -65 -91 -33 -7 49 1 56 30 -43 32 -63 -57 35 50 74 -86 -66 -19 34 36
4949
# 55 -46 -25 -27 99 71 38 -98 72 -81 68 66 84 -14 17 -86 76 -36 88 -54 29 33 -98 -94 -44 79 16 -16 7 53
5050
# -53 -34 -39 -93 -42 -79 95 24 66 -94 -8 -38 -37 45 -9 26 86 75 -59 -2 -80 -61 -68 -66 -59 -41 -18 8 26 -24
51-
# 72 23 -31 -8 70 38 98 95 97 57 -90 -88 -89 -26 -62 89 67 22 -94 48 33 20 -7 -87 -94 33 -81 80 -64 87
51+
# 72 23 -31 -8 70 38 98 95 97 57 -90 -88 -89 -26 -62 89 67 22 -94 48 33 20 -7 -87 -94 33 -81 80 -64 87

HackerRank/Flipping-the-Matrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ def flippingMatrix(matrix):
66
ans = 0
77
for i in range(n):
88
for j in range(n):
9-
ans += max(matrix[i][j],matrix[i][2*n-1-j],matrix[2*n-1-i][j],matrix[2*n-1-i][2*n-1-j])
9+
ans += max(matrix[i][j], matrix[i][2*n-1-j], matrix[2*n-1-i][j], matrix[2*n-1-i][2*n-1-j])
1010
return ans
1111

12-
##Note: I'll document this solution
12+
# Note: I'll document this solution
1313

14-
# Status: Accepted
14+
# Status: Accepted

HackerRank/Grading-Students.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# https://www.hackerrank.com/challenges/grading/problem
33

44
def gradingStudents(grades):
5-
for index,grade in enumerate(grades):
6-
if grade%5 >= 3 and grade >= 38:
7-
grades[index] += 5-grade%5
5+
for index, grade in enumerate(grades):
6+
if grade % 5 >= 3 and grade >= 38:
7+
grades[index] += 5-grade % 5
88
return grades
99

1010
# Testcases
1111
# 73 67 38 33 - 75 67 40 33
1212

13-
# Status - Passed
13+
# Status - Passed

HackerRank/Lonely-Integer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
def lonelyinteger(a):
55
for i in a:
6-
if a.count(i) == 1:
7-
return i
6+
if a.count(i) == 1:
7+
return i
88
break
99

1010
# Testcases
11-
# 0 0 1 2 1 - 2
11+
# 0 0 1 2 1 - 2
1212
# 1 1 2 - 2
1313
# 1 2 3 4 3 2 1 - 4
1414

15-
# Status - Passed
15+
# Status - Passed

0 commit comments

Comments
 (0)