diff --git a/HackerRank-A Very Big Sum/A_Very_Big_Sum.py b/HackerRank-A Very Big Sum/A_Very_Big_Sum.py index bc7e073..9f5ed0f 100644 --- a/HackerRank-A Very Big Sum/A_Very_Big_Sum.py +++ b/HackerRank-A Very Big Sum/A_Very_Big_Sum.py @@ -5,12 +5,10 @@ import random import re import sys + # Complete the aVeryBigSum function below. def aVeryBigSum(ar): - sum = 0 - for i in range(len(ar)): - sum+=ar[i] - return sum + return sum(ar) if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') diff --git a/HackerRank-Apple and Orange/Apple_and_Orange.py b/HackerRank-Apple and Orange/Apple_and_Orange.py index f5bad10..4c89c02 100644 --- a/HackerRank-Apple and Orange/Apple_and_Orange.py +++ b/HackerRank-Apple and Orange/Apple_and_Orange.py @@ -8,20 +8,8 @@ # Complete the countApplesAndOranges function below. def countApplesAndOranges(s, t, a, b, apples, oranges): - acount = 0 - bcount = 0 - for i in range(len(apples)): - temp = a+apples[i] - if(temp in range(s,t+1)): - acount+=1 - for i in range(len(oranges)): - temp = b+oranges[i] - if(temp in range(s,t+1)): - bcount+=1 - print (acount) - print (bcount) - - + print(len([a+i for i in apples if a+i >= s and a+i <= t ])) + print(len([b+i for i in oranges if b+i >= s and b+i <= t])) if __name__ == '__main__': st = input().split() diff --git a/HackerRank-Diagonal Difference/Diagonal_Difference.py b/HackerRank-Diagonal Difference/Diagonal_Difference.py index 7cfabd2..b29761d 100644 --- a/HackerRank-Diagonal Difference/Diagonal_Difference.py +++ b/HackerRank-Diagonal Difference/Diagonal_Difference.py @@ -6,21 +6,20 @@ import re import sys -# Complete the diagonalDifference function below. +# +# Complete the 'diagonalDifference' function below. +# +# The function is expected to return an INTEGER. +# The function accepts 2D_INTEGER_ARRAY arr as parameter. +# + def diagonalDifference(arr): - prim =0 - sec=0 - length = len(arr[0]) - for count in range(length): - prim += arr[count][count] - sec += arr[count][(length-count-1)] - return abs(prim-sec) - + return abs(sum([arr[i][i] for i in range(len(arr))])-sum([arr[i][len(arr)-i-1] for i in range(len(arr))])) if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') - n = int(input()) + n = int(input().strip()) arr = [] diff --git a/HackerRank-Extra Long Factorials/Extra_Long_Factorials.py b/HackerRank-Extra Long Factorials/Extra_Long_Factorials.py index 8bd1b70..fed06d9 100644 --- a/HackerRank-Extra Long Factorials/Extra_Long_Factorials.py +++ b/HackerRank-Extra Long Factorials/Extra_Long_Factorials.py @@ -8,13 +8,9 @@ # Complete the extraLongFactorials function below. def extraLongFactorials(n): - ans=1 - while(n!=1): - ans*=n - n-=1 - print (ans) + if n == 1: + return 1 + return n * extraLongFactorials(n-1) if __name__ == '__main__': - n = int(input()) - - extraLongFactorials(n) + print(extraLongFactorials(int(input()))) diff --git a/HackerRank-Mini-Max Sum/Mini-Max_Sum.py b/HackerRank-Mini-Max Sum/Mini-Max_Sum.py index b4ea822..48d4233 100644 --- a/HackerRank-Mini-Max Sum/Mini-Max_Sum.py +++ b/HackerRank-Mini-Max Sum/Mini-Max_Sum.py @@ -8,12 +8,8 @@ # Complete the miniMaxSum function below. def miniMaxSum(arr): - sum=0 - for i in range(len(arr)): - sum+=arr[i] - print ( sum-max(arr), sum-min(arr)) - + s=sum(arr) + print(s-max(arr),s-min(arr)) if __name__ == '__main__': arr = list(map(int, input().rstrip().split())) - miniMaxSum(arr) diff --git a/HackkerRank-Angry Professor/Angry_Professor.py b/HackkerRank-Angry Professor/Angry_Professor.py index a5a27a8..ee5ad9e 100644 --- a/HackkerRank-Angry Professor/Angry_Professor.py +++ b/HackkerRank-Angry Professor/Angry_Professor.py @@ -8,14 +8,7 @@ # Complete the angryProfessor function below. def angryProfessor(k, a): - count=0 - for i in range(len(a)): - if(a[i]<=0): - count+=1 - if(count>=k): - return "NO" - return "YES" - + return "NO" if len(list(filter(lambda x:x<=0, a)))>=k else "YES" if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w')
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: