Skip to content

Commit

Permalink
Add challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
kilian-hu committed Nov 21, 2021
1 parent 707eb07 commit 560c7b1
Show file tree
Hide file tree
Showing 54 changed files with 2,218 additions and 0 deletions.
55 changes: 55 additions & 0 deletions challenges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Challenges

- [A Very Big Sum](a-very-big-sum.py) [[url]](https://www.hackerrank.com/challenges/a-very-big-sum) [10p]
- [ACM ICPC Team](acm-icpc-team.py) [[url]](https://www.hackerrank.com/challenges/acm-icpc-team) [25p]
- [Angry Professor](angry-professor.py) [[url]](https://www.hackerrank.com/challenges/angry-professor) [20p]
- [Append and Delete](append-and-delete.py) [[url]](https://www.hackerrank.com/challenges/append-and-delete) [20p]
- [Apple and Orange](apple-and-orange.py) [[url]](https://www.hackerrank.com/challenges/apple-and-orange) [10p]
- [Beautiful Days at the Movies](beautiful-days-at-the-movies.py) [[url]](https://www.hackerrank.com/challenges/beautiful-days-at-the-movies) [15p]
- [Between Two Sets](between-two-sets.py) [[url]](https://www.hackerrank.com/challenges/between-two-sets) [10p]
- [Bill Division](bon-appetit.py) [[url]](https://www.hackerrank.com/challenges/bon-appetit) [10p]
- [Birthday Cake Candles](birthday-cake-candles.py) [[url]](https://www.hackerrank.com/challenges/birthday-cake-candles) [10p]
- [Breaking the Records](breaking-best-and-worst-records.py) [[url]](https://www.hackerrank.com/challenges/breaking-best-and-worst-records) [10p]
- [Cats and a Mouse](cats-and-a-mouse.py) [[url]](https://www.hackerrank.com/challenges/cats-and-a-mouse) [15p]
- [Circular Array Rotation](circular-array-rotation.py) [[url]](https://www.hackerrank.com/challenges/circular-array-rotation) [20p]
- [Climbing the Leaderboard](climbing-the-leaderboard.py) [[url]](https://www.hackerrank.com/challenges/climbing-the-leaderboard) [20p]
- [Compare the Triplets](compare-the-triplets.py) [[url]](https://www.hackerrank.com/challenges/compare-the-triplets) [10p]
- [Counting Valleys](counting-valleys.py) [[url]](https://www.hackerrank.com/challenges/counting-valleys) [15p]
- [Cut the sticks](cut-the-sticks.py) [[url]](https://www.hackerrank.com/challenges/cut-the-sticks) [25p]
- [Day of the Programmer](day-of-the-programmer.py) [[url]](https://www.hackerrank.com/challenges/day-of-the-programmer) [15p]
- [Designer PDF Viewer](designer-pdf-viewer.py) [[url]](https://www.hackerrank.com/challenges/designer-pdf-viewer) [20p]
- [Diagonal Difference](diagonal-difference.py) [[url]](https://www.hackerrank.com/challenges/diagonal-difference) [10p]
- [Divisible Sum Pairs](divisible-sum-pairs.py) [[url]](https://www.hackerrank.com/challenges/divisible-sum-pairs) [10p]
- [Drawing Book](drawing-book.py) [[url]](https://www.hackerrank.com/challenges/drawing-book) [10p]
- [Electronics Shop](electronics-shop.py) [[url]](https://www.hackerrank.com/challenges/electronics-shop) [15p]
- [Equalize the Array](equality-in-a-array.py) [[url]](https://www.hackerrank.com/challenges/equality-in-a-array) [20p]
- [Extra Long Factorials](extra-long-factorials.py) [[url]](https://www.hackerrank.com/challenges/extra-long-factorials) [20p]
- [Find Digits](find-digits.py) [[url]](https://www.hackerrank.com/challenges/find-digits) [25p]
- [Forming a Magic Square](magic-square-forming.py) [[url]](https://www.hackerrank.com/challenges/magic-square-forming) [20p]
- [Frog in Maze](frog-in-maze.py) [[url]](https://www.hackerrank.com/challenges/frog-in-maze) [65p]
- [Grading Students](grading.py) [[url]](https://www.hackerrank.com/challenges/grading) [10p]
- [Jumping on the Clouds: Revisited](jumping-on-the-clouds-revisited.py) [[url]](https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited) [15p]
- [Jumping on the Clouds](jumping-on-the-clouds.py) [[url]](https://www.hackerrank.com/challenges/jumping-on-the-clouds) [20p]
- [Library Fine](library-fine.py) [[url]](https://www.hackerrank.com/challenges/library-fine) [15p]
- [Migratory Birds](migratory-birds.py) [[url]](https://www.hackerrank.com/challenges/migratory-birds) [10p]
- [Mini-Max Sum](mini-max-sum.py) [[url]](https://www.hackerrank.com/challenges/mini-max-sum) [10p]
- [Non-Divisible Subset](non-divisible-subset.py) [[url]](https://www.hackerrank.com/challenges/non-divisible-subset) [20p]
- [Number Line Jumps](kangaroo.py) [[url]](https://www.hackerrank.com/challenges/kangaroo) [10p]
- [Organizing Containers of Balls](organizing-containers-of-balls.py) [[url]](https://www.hackerrank.com/challenges/organizing-containers-of-balls) [30p]
- [Picking Numbers](picking-numbers.py) [[url]](https://www.hackerrank.com/challenges/picking-numbers) [20p]
- [Plus Minus](plus-minus.py) [[url]](https://www.hackerrank.com/challenges/plus-minus) [10p]
- [Queen's Attack II](queens-attack-2.py) [[url]](https://www.hackerrank.com/challenges/queens-attack-2) [30p]
- [Repeated String](repeated-string.py) [[url]](https://www.hackerrank.com/challenges/repeated-string) [20p]
- [Sales by Match](sock-merchant.py) [[url]](https://www.hackerrank.com/challenges/sock-merchant) [10p]
- [Save the Prisoner!](save-the-prisoner.py) [[url]](https://www.hackerrank.com/challenges/save-the-prisoner) [15p]
- [Sequence Equation](permutation-equation.py) [[url]](https://www.hackerrank.com/challenges/permutation-equation) [20p]
- [Sherlock and Cost](sherlock-and-cost.py) [[url]](https://www.hackerrank.com/challenges/sherlock-and-cost) [50p]
- [Sherlock and Squares](sherlock-and-squares.py) [[url]](https://www.hackerrank.com/challenges/sherlock-and-squares) [20p]
- [Simple Array Sum](simple-array-sum.py) [[url]](https://www.hackerrank.com/challenges/simple-array-sum) [10p]
- [Staircase](staircase.py) [[url]](https://www.hackerrank.com/challenges/staircase) [10p]
- [Subarray Division](the-birthday-bar.py) [[url]](https://www.hackerrank.com/challenges/the-birthday-bar) [10p]
- [Taum and B'day](taum-and-bday.py) [[url]](https://www.hackerrank.com/challenges/taum-and-bday) [25p]
- [The Hurdle Race](the-hurdle-race.py) [[url]](https://www.hackerrank.com/challenges/the-hurdle-race) [15p]
- [Time Conversion](time-conversion.py) [[url]](https://www.hackerrank.com/challenges/time-conversion) [15p]
- [Utopian Tree](utopian-tree.py) [[url]](https://www.hackerrank.com/challenges/utopian-tree) [20p]
- [Viral Advertising](strange-advertising.py) [[url]](https://www.hackerrank.com/challenges/strange-advertising) [15p]
30 changes: 30 additions & 0 deletions challenges/a-very-big-sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'aVeryBigSum' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_INTEGER_ARRAY ar as parameter.
#

def aVeryBigSum(ar):
return sum(ar)

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

ar_count = int(input().strip())

ar = list(map(int, input().rstrip().split()))

result = aVeryBigSum(ar)

fptr.write(str(result) + '\n')

fptr.close()
49 changes: 49 additions & 0 deletions challenges/acm-icpc-team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'acmTeam' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts STRING_ARRAY topic as parameter.
#

def acmTeam(topic):
most = 0
most_cnt = 0
for i in range(len(topic) - 1):
for j in range(i + 1, len(topic)):
x = sum(t1 == "1" or t2 == "1" for t1, t2 in zip(topic[i], topic[j]))
if x > most:
most = x
most_cnt = 1
elif x == most:
most_cnt += 1
return most, most_cnt

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

first_multiple_input = input().rstrip().split()

n = int(first_multiple_input[0])

m = int(first_multiple_input[1])

topic = []

for _ in range(n):
topic_item = input()
topic.append(topic_item)

result = acmTeam(topic)

fptr.write('\n'.join(map(str, result)))
fptr.write('\n')

fptr.close()
39 changes: 39 additions & 0 deletions challenges/angry-professor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'angryProfessor' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. INTEGER k
# 2. INTEGER_ARRAY a
#

def angryProfessor(k, a):
return "YES" if sum(x <= 0 for x in a) < k else "NO"

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

t = int(input().strip())

for t_itr in range(t):
first_multiple_input = input().rstrip().split()

n = int(first_multiple_input[0])

k = int(first_multiple_input[1])

a = list(map(int, input().rstrip().split()))

result = angryProfessor(k, a)

fptr.write(result + '\n')

fptr.close()
42 changes: 42 additions & 0 deletions challenges/append-and-delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'appendAndDelete' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING s
# 2. STRING t
# 3. INTEGER k
#

def appendAndDelete(s, t, k):
i = 0
while i < min(len(s), len(t)) and s[i] == t[i]:
i += 1
x = len(s) + len(t) - (2 * i)
if x <= k and ((k - x) % 2 == 0 or (len(s) + len(t)) <= k):
return "Yes"
else:
return "No"

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

s = input()

t = input()

k = int(input().strip())

result = appendAndDelete(s, t, k)

fptr.write(result + '\n')

fptr.close()
48 changes: 48 additions & 0 deletions challenges/apple-and-orange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'countApplesAndOranges' function below.
#
# The function accepts following parameters:
# 1. INTEGER s
# 2. INTEGER t
# 3. INTEGER a
# 4. INTEGER b
# 5. INTEGER_ARRAY apples
# 6. INTEGER_ARRAY oranges
#

def countApplesAndOranges(s, t, a, b, apples, oranges):
print(sum([s <= a + x <= t for x in apples]))
print(sum([s <= b + x <= t for x in oranges]))

if __name__ == '__main__':
first_multiple_input = input().rstrip().split()

s = int(first_multiple_input[0])

t = int(first_multiple_input[1])

second_multiple_input = input().rstrip().split()

a = int(second_multiple_input[0])

b = int(second_multiple_input[1])

third_multiple_input = input().rstrip().split()

m = int(third_multiple_input[0])

n = int(third_multiple_input[1])

apples = list(map(int, input().rstrip().split()))

oranges = list(map(int, input().rstrip().split()))

countApplesAndOranges(s, t, a, b, apples, oranges)
37 changes: 37 additions & 0 deletions challenges/beautiful-days-at-the-movies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'beautifulDays' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER i
# 2. INTEGER j
# 3. INTEGER k
#

def beautifulDays(i, j, k):
return sum(abs(x - int(str(x)[::-1])) % k == 0 for x in range(i, j + 1))

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

first_multiple_input = input().rstrip().split()

i = int(first_multiple_input[0])

j = int(first_multiple_input[1])

k = int(first_multiple_input[2])

result = beautifulDays(i, j, k)

fptr.write(str(result) + '\n')

fptr.close()
41 changes: 41 additions & 0 deletions challenges/between-two-sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'getTotalX' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY a
# 2. INTEGER_ARRAY b
#

def getTotalX(a, b):
res = 0
for i in range(max(a), min(b) + 1):
res += (all([i % aa == 0 for aa in a]) and all([bb % i == 0 for bb in b]))
return res

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

first_multiple_input = input().rstrip().split()

n = int(first_multiple_input[0])

m = int(first_multiple_input[1])

arr = list(map(int, input().rstrip().split()))

brr = list(map(int, input().rstrip().split()))

total = getTotalX(arr, brr)

fptr.write(str(total) + '\n')

fptr.close()
38 changes: 38 additions & 0 deletions challenges/birthday-cake-candles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'birthdayCakeCandles' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY candles as parameter.
#

def birthdayCakeCandles(candles):
m = 0
res = 0
for c in candles:
if c > m:
m = c
res = 1
elif c == m:
res += 1
return res

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

candles_count = int(input().strip())

candles = list(map(int, input().rstrip().split()))

result = birthdayCakeCandles(candles)

fptr.write(str(result) + '\n')

fptr.close()
Loading

0 comments on commit 560c7b1

Please sign in to comment.