Skip to content

Commit 621931f

Browse files
committed
Cleanup
1 parent 42dbfd9 commit 621931f

15 files changed

+18
-135
lines changed

hackerrank/acm_icpc_team.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Import packages
22
from typing import List
33

4-
54
def acm_team(topic: List[str]) -> List[int]:
6-
# Convert string to binary
75
topic = [int(t, 2) for t in topic]
8-
96
max_topics, num_teams = 0, 0
107

118
for i in range(len(topic) - 1):
@@ -23,10 +20,8 @@ def acm_team(topic: List[str]) -> List[int]:
2320

2421

2522
if __name__ == "__main__":
26-
# Read input from stdin
2723
n, m = list(map(int, input().strip().split()))
2824

29-
# Read topic input from stdin
3025
topic = list()
3126
for _ in range(n):
3227
topic_item = input()

hackerrank/angry_professor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ def angry_professor(k: int, arr: list) -> str:
33

44

55
if __name__ == "__main__":
6-
# Read number test cases
76
num_test = int(input().strip())
87

98
for t in range(num_test):
10-
# Read students in class (n) and cancelation threshold (k)
119
n, k = map(int, input().strip().split())
1210

13-
# Read n-separated integers describing student arrival times
1411
arr = list(map(int, input().rstrip().split()))
1512
arr = sorted(arr, key=int)
1613

17-
# Determine if class is canceled
1814
print("Is class canceled:", angry_professor(k, arr))

hackerrank/athlete_sort.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
if __name__ == "__main__":
2-
# Read number of rows and columns from stdin
32
rows, columns = list(map(int, input().strip().split()))
43

5-
# Read data points from stdin
64
data = list()
75
for i in range(rows):
86
data.append(list(map(int, input().strip().split())))
97

10-
# Read sprting index from stdin
118
sort_col_index = int(input().strip())
129

13-
# Sort data using a particular column index
1410
for row in sorted(data, key=lambda t: t[sort_col_index]):
1511
print(" ".join([str(x) for x in row]).strip())

hackerrank/beautiful_days.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
if __name__ == "__main__":
2-
# Read input from stdin
32
n, m, k = list(map(int, input().strip().split()))
43

5-
# Count beautiful days
64
count = 0
75
for x in range(n, m+1):
86
y = int(str(x)[::-1])

hackerrank/captains_room.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
def find_captains_room(rooms, size):
22
all_guests = list(map(int, rooms))
3+
34
unique_guests = set(all_guests)
45
sum_all_guests = sum(all_guests)
56

6-
# Get the sum of all the unique room numbers
77
sum_unique_guests = sum(unique_guests)
8-
9-
# Get the difference, in the sum: the captains room will cause this difference
108
temp = (sum_unique_guests * size) - sum_all_guests
119

12-
# Compute the captain's room number
1310
return temp // (size - 1)
1411

1512

1613
if __name__ == "__main__":
17-
# Read input size from stdin
1814
size = int(input().strip())
19-
20-
# Read room number list from stdin
2115
rooms = input().strip().split(" ")
2216

23-
# Find captain's room
2417
captains_room_number = find_captains_room(rooms, size)
25-
2618
print(captains_room_number)

hackerrank/designer_door_mat.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
if __name__ == "__main__":
2-
# Read input from stdin
32
n, m = input().strip().split(" ")
43
n, m = [int(n), int(m)]
54

6-
# Draw top half
75
for i in range(1, n, 2):
86
print("-" * ((m - i * 3) // 2) + ("|".center(3, "."))
97
* i + "-" * ((m - i * 3) // 2))
108

11-
# Print message
12-
print("WELCOmE".center(m, "-"))
9+
print("WELCOME".center(m, "-"))
1310

14-
# Draw bottom half
1511
for i in range(n - 2, -1, -2):
1612
print("-" * ((m - i * 3) // 2) + ("|".center(3, "."))
1713
* i + "-" * ((m - i * 3) // 2))

hackerrank/find_angle.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
# Import packages
22
from math import degrees, hypot, acos
33

4-
54
def compute_angle(ab, bc):
6-
# Compute larger triangle hypotenuse
7-
hypotenuse = hypot(ab, bc)
8-
9-
# Compute angle using arc cosine (base / hypotenuse)
10-
return int(round(degrees(acos(bc/hypotenuse))))
5+
return int(round(degrees(acos(bc/hypot(ab, bc)))))
116

127

138
if __name__ == "__main__":
14-
# Read triangle side input from stdin
159
ab = int(input().strip())
1610
bc = int(input().strip())
1711

18-
# Compute angle at mbc
1912
angle = compute_angle(ab, bc)
20-
21-
# Print angle with degree symbol
2213
print(f"Computed Angle: {angle}{chr(176)}")

hackerrank/get_node_value.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,31 @@
1-
class SinglyLinkedListNode:
2-
"""Node class implementation.
3-
"""
4-
5-
def __init__(self, node_data):
1+
class Node:
2+
def __init__(self, node_data: int) -> None:
63
self.data = node_data
74
self.next = None
85

9-
106
class SinglyLinkedList:
11-
"""Singly linked list class implementation.
12-
"""
13-
14-
def __init__(self):
7+
def __init__(self) -> None:
158
self.head = None
169
self.tail = None
1710

18-
def insert_node(self, node_data):
19-
# Create a new node
20-
node = SinglyLinkedListNode(node_data)
11+
def insert_node(self, node_data) -> None:
12+
node = Node(node_data)
2113

2214
if not self.head:
23-
# Add ndoe to head when list is empty
2415
self.head = node
2516
else:
26-
# Add node to tail when list is not empty
2717
self.tail.next = node
2818

29-
# Set new node as tail
3019
self.tail = node
3120

32-
33-
def get_node(head, pos_from_tail):
34-
# Count number of nodes in the list
21+
def get_node(head, pos_from_tail) -> int:
3522
num_nodes = 0
3623

3724
curr = head
3825
while curr:
3926
num_nodes += 1
4027
curr = curr.next
4128

42-
# Now identify the node relative to tail
4329
pos_from_head = 0
4430

4531
curr = head
@@ -51,28 +37,18 @@ def get_node(head, pos_from_tail):
5137

5238

5339
if __name__ == "__main__":
54-
# Read numer of test cases from stdin
5540
tests = int(input().strip())
5641

57-
# For each test case
5842
for t in range(tests):
59-
# Read number of elements from stdin
6043
num_elements = int(input().strip())
6144

62-
# Initiate singly linked list class
6345
llist = SinglyLinkedList()
6446

65-
# For each element
6647
for _ in range(num_elements):
67-
# Read list input from stdin
6848
item = int(input().strip())
69-
70-
# Insert input into list
7149
llist.insert_node(item)
7250

73-
# Read position relative to tail from stdin
7451
position = int(input().strip())
7552

76-
# Get data stored at node for the given position
7753
node_value = get_node(llist.head, position)
7854
print("Node Value:", node_value)

hackerrank/merge_the_tools.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
def create_sequences(sequence, factor):
2-
# Compute sequence and new sequence length
32
seq_len = len(sequence)
43

5-
# Iteratively create new sequences
64
for i in range(0, seq_len, factor):
7-
# Unique character set placeholder
85
seen = set()
96
for char in sequence[i:i+factor]:
107
if char not in seen:
11-
# If not seen, print
128
seen.add(char)
139
print(char, end="")
1410
else:
15-
# If seen, ignore
1611
continue
17-
# Add newline for next sequence
1812
print()
1913

2014

2115
if __name__ == "__main__":
22-
# Read sequenc string from stdin
2316
sequence = input().strip()
24-
25-
# Read factor integer from stdin
2617
factor = int(input().strip())
2718

28-
# Print new sequences on newlines
2919
create_sequences(sequence, factor)

hackerrank/piling_up.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,64 @@
1-
def piling_up(num_blocks, block_lengths):
2-
# Set dummy top value
1+
def piling_up(num_blocks: int, block_lengths: int) -> bool:
32
top = -1
3+
left, right = 0,
4+
num_blocks - 1
45

5-
# Set left and right pointers
6-
left, right = 0, num_blocks - 1
6+
if_first, flag = True, True
77

8-
# Set flag to denote first iteration
9-
if_first = True
10-
11-
# Set flag to indicate if piling is possible
12-
flag = True
13-
14-
# Iterate over the block lengths using two pointers
158
while left < right:
16-
# Find the largest block length
179
if block_lengths[left] > block_lengths[right]:
1810
if if_first:
19-
# First iteration
2011
top = block_lengths[left]
2112
left += 1
2213

23-
# Reset flag to avoid running this block for other iterations
2414
if_first = False
2515
else:
2616
if block_lengths[left] <= top:
2717
top = block_lengths[left]
2818
left += 1
2919
else:
30-
# Reset piling up flag when rule failes and break
3120
flag = False
3221
break
3322
elif block_lengths[left] < block_lengths[right]:
3423
if if_first:
35-
# First iteration
3624
top = block_lengths[right]
3725
right -= 1
3826

39-
# Reset flag to avoid running this block for other iterations
4027
if_first = False
4128
else:
4229
if block_lengths[right] <= top:
4330
top = block_lengths[right]
4431
left += 1
4532
else:
46-
# Reset piling up flag when rule failes and break
4733
flag = False
4834
break
4935
else:
5036
if if_first:
51-
# First iteration
5237
top = block_lengths[left]
5338
left += 1
5439
right -= 1
5540

56-
# Reset flag to avoid running this block for other iterations
5741
if_first = False
5842
else:
5943
if block_lengths[left] <= top:
6044
top = block_lengths[left]
6145
left += 1
6246
right -= 1
6347
else:
64-
# Reset piling up flag when rule failes and break
6548
flag = False
6649
break
6750
return flag
6851

6952

7053
if __name__ == "__main__":
71-
# Read number test cases from stdin
7254
test_cases = int(input().strip())
7355

74-
# For each test case
7556
for t in range(test_cases):
76-
# Read number of blocks from stdin
7757
num_blocks = int(input().strip())
7858

79-
# Read block side lengths from stdin
8059
block_lengths = list(map(int, input().strip().split()))
81-
82-
# Check for piling
8360
flag = piling_up(num_blocks, block_lengths)
8461

85-
# Print appropriate message
8662
if flag:
8763
print("Yes")
8864
else:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy