Skip to content

Commit fe3fdb1

Browse files
authored
Add files via upload
1 parent 7e90021 commit fe3fdb1

3 files changed

Lines changed: 127 additions & 0 deletions

File tree

problem_solving/CompareTriplets.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'compareTriplets' function below.
11+
#
12+
# The function is expected to return an INTEGER_ARRAY.
13+
# The function accepts following parameters:
14+
# 1. INTEGER_ARRAY a
15+
# 2. INTEGER_ARRAY b
16+
#
17+
18+
def compareTriplets(a, b):
19+
# Write your code here
20+
score = [0, 0]
21+
for i in range(3):
22+
if a[i] == b[i]:
23+
pass
24+
elif a[i] > b[i]:
25+
score[0] += 1
26+
else:
27+
score[1] += 1
28+
29+
return score
30+
31+
if __name__ == '__main__':
32+
#fptr = open(os.environ['OUTPUT_PATH'], 'w')
33+
34+
a = list(map(int, input().rstrip().split()))
35+
36+
b = list(map(int, input().rstrip().split()))
37+
38+
result = compareTriplets(a, b)
39+
40+
#fptr.write(' '.join(map(str, result)))
41+
#fptr.write('\n')
42+
43+
#fptr.close()
44+
45+
print(result)

problem_solving/aVeryBigSum.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'aVeryBigSum' function below.
11+
#
12+
# The function is expected to return a LONG_INTEGER.
13+
# The function accepts LONG_INTEGER_ARRAY ar as parameter.
14+
#
15+
16+
def aVeryBigSum(ar):
17+
# Write your code here
18+
return sum(ar)
19+
20+
if __name__ == '__main__':
21+
#fptr = open(os.environ['OUTPUT_PATH'], 'w')
22+
23+
ar_count = int(input().strip())
24+
25+
ar = list(map(int, input().rstrip().split()))
26+
27+
result = aVeryBigSum(ar)
28+
29+
#fptr.write(str(result) + '\n')
30+
31+
#fptr.close()
32+
print(result)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'diagonalDifference' function below.
11+
#
12+
# The function is expected to return an INTEGER.
13+
# The function accepts 2D_INTEGER_ARRAY arr as parameter.
14+
#
15+
16+
def diagonalDifference(arr):
17+
# Write your code here
18+
last_index = len(arr) -1
19+
left_to_right_diagonal_sum = 0
20+
right_to_left_diagonal_sum = 0
21+
i, j = 0, 0
22+
while (i <= last_index):
23+
left_to_right_diagonal_sum += arr[i][j]
24+
i+=1
25+
j+=1
26+
27+
p,q = last_index, 0
28+
while (p >= 0):
29+
right_to_left_diagonal_sum += arr[p][q]
30+
p-=1
31+
q+=1
32+
33+
return abs(left_to_right_diagonal_sum - right_to_left_diagonal_sum)
34+
35+
if __name__ == '__main__':
36+
#fptr = open(os.environ['OUTPUT_PATH'], 'w')
37+
38+
n = int(input().strip())
39+
40+
arr = []
41+
42+
for _ in range(n):
43+
arr.append(list(map(int, input().rstrip().split())))
44+
45+
result = diagonalDifference(arr)
46+
print(result)
47+
48+
#fptr.write(str(result) + '\n')
49+
50+
#fptr.close()

0 commit comments

Comments
 (0)