Skip to content

Commit c8d0a51

Browse files
committed
Hackerrank program leap year
1 parent 34196fd commit c8d0a51

File tree

9 files changed

+58
-31
lines changed

9 files changed

+58
-31
lines changed

Notes/1.Basic/file_path

Lines changed: 0 additions & 1 deletion
This file was deleted.

Notes/1.Basic/filename.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

hackerrank/alonelyinteger.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
def lonelyinteger(a):
2-
b=sorted(a)
3-
if len(b)==1:
2+
b = sorted(a)
3+
if len(b) == 1:
44
return b[0]
55
else:
6-
for i in range(len(b)):
7-
count=0
6+
for i in range(len(b)):
7+
count = 0
88
for j in range(len(b)):
9-
if b[i]==b[j]:
10-
count+=1
11-
if count==1:
9+
if b[i] == b[j]:
10+
count += 1
11+
if count == 1:
1212
return b[i]
13-
14-
a=list(map(int,input().split()))
15-
print(lonelyinteger(a))
13+
14+
15+
def lonelyinteger(a):
16+
b = sorted(a)
17+
data = {}
18+
if len(b) == 1:
19+
return b[0]
20+
else:
21+
for i in b:
22+
if i in data:
23+
data[i] += 1
24+
else:
25+
data[i] = 1
26+
for key, value in data.items():
27+
if value == 1:
28+
return key
29+
30+
31+
a = list(map(int, input().split()))
32+
print(lonelyinteger(a))

hackerrank/diagonaldifference.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
def diagonalDifference(arr):
22
# Write your code here
3-
c=0
4-
d=0
5-
n=len(arr)
3+
c = 0
4+
d = 0
5+
n = len(arr)
66
for i in range(n):
7-
c+=arr[i][i]
8-
d+=arr[i][n-i-1]
7+
c += arr[i][i]
8+
d += arr[i][n - i - 1]
99
# a=c-d
10-
return abs(c-d)
10+
return abs(c - d)
11+
1112

1213
n = int(input().strip())
1314

@@ -23,7 +24,7 @@ def diagonalDifference(arr):
2324
# For example, the square matrix arr is shown below:
2425
# 1 2 3
2526
# 4 5 6
26-
# 9 8 9
27-
# The left-to-right diagonal = 1+5+9 = 15.
28-
# The right to left diagonal = 3+5+9=17.
27+
# 9 8 9
28+
# The left-to-right diagonal = 1+5+9 = 15.
29+
# The right to left diagonal = 3+5+9=17.
2930
# Their absolute difference is |15-17| = 2.

hackerrank/findthepercentage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Find the Percentage of the student name
2-
if __name__ == '__main__':
2+
if __name__ == "__main__":
33
n = int(input())
44
student_marks = {}
55
for _ in range(n):
66
name, *line = input().split()
77
scores = list(map(float, line))
88
student_marks[name] = scores
9-
query_name = input()# student name search average
10-
i=0
11-
d=student_marks[query_name]
12-
i=sum(d)/3
9+
query_name = input() # student name search average
10+
i = 0
11+
d = student_marks[query_name]
12+
i = sum(d) / 3
1313

14-
print("%.2f"%i)
14+
print("%.2f" % i)
1515

16-
# using for loop enumerate function
16+
# using for loop enumerate function
1717
# for j,k in enumerate(d):
1818
# i+=k
1919
# i=i/3

hackerrank/findtherunnerscore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if __name__ == '__main__':
1+
if __name__ == "__main__":
22
n = int(input())
3-
arr =map(int, input().split())
3+
arr = map(int, input().split())
44
print(sorted(list(set(arr)))[-2])

hackerrank/hash_tuple.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ def hash_tup():
22
n = int(input())
33
integer_list = map(int, input().split())
44
print(hash(tuple(integer_list)))
5-
hash_tup()
5+
6+
7+
hash_tup()

hackerrank/leap_year.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def is_leap(year):
2+
leap = False
3+
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
4+
leap = True
5+
return leap
6+
7+
8+
year = int(input())
9+
print(is_leap(year))

0 commit comments

Comments
 (0)