Skip to content

Commit 799c6e0

Browse files
committed
Adding hackerrank 30 days of code solutions
1 parent 58de795 commit 799c6e0

File tree

86 files changed

+1049
-1808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1049
-1808
lines changed
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Read a full line of input from stdin and save it to our dynamically typed variable
2+
input_string = input()
3+
4+
# Print a string literal saying "Hello, World." to stdout
5+
print("Hello, World.")
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Declare first integer, double and string variables
2+
i = 4
3+
d = 4.0
4+
s = "HackerRank "
5+
6+
# Read and save an integer, double, and String to your variables
7+
input_i = int(input())
8+
input_d = float(input())
9+
input_s = input()
10+
11+
# Print the sum of both integer variables on a new line
12+
print(i + input_i)
13+
14+
# Print the sum of the double variables on a new line
15+
print(d + input_d)
16+
17+
# Concatenate and print the String variables on a new line
18+
# The 's' variable above should be printed first
19+
print(s + input_s)
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
def count_ones(binary_number):
3+
max_count, count = 0, 0
4+
flag = False
5+
6+
for b in binary_number:
7+
if b == "1":
8+
if flag == False:
9+
# Start counting
10+
count += 1
11+
flag = True
12+
elif flag == True:
13+
# Keep counting
14+
count += 1
15+
elif b == "0":
16+
if flag == True:
17+
# Stop counting
18+
max_count = max(max_count, count)
19+
20+
# Reset
21+
count = 0
22+
flag = False
23+
elif flag == False:
24+
# Do nothing
25+
continue
26+
# In case last binary literal is 1
27+
# Counting never stopped
28+
max_count = max(max_count, count)
29+
return max_count
30+
31+
32+
if __name__ == "__main__":
33+
# Read integer input from stdin
34+
n = int(input().strip())
35+
36+
# Conver input integer to binary
37+
# Remove binary literals "0b"
38+
binary_rep = bin(n)[2:]
39+
40+
# Count consecutive 1s
41+
max_consecutive_ones = count_ones(binary_rep)
42+
43+
print(max_consecutive_ones)
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
if __name__ == "__main__":
3+
# Array placeholder
4+
A = list()
5+
6+
# Read 2D array input from stdin
7+
for _ in range(6):
8+
A.append(list(map(int, input().rstrip().split())))
9+
10+
maxsum = -999
11+
12+
# Traverse through 2D array and compute sum
13+
for i in range(4):
14+
for j in range(4):
15+
value = A[i][j] + A[i][j+1] + A[i][j+2] + A[i+1][j+1] + A[i+2][j] + A[i+2][j+1] + A[i+2][j+2]
16+
if value > maxsum:
17+
maxsum = value
18+
else:
19+
continue
20+
21+
print(maxsum)
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
# Parent class
3+
class Person:
4+
5+
def __init__(self, firstName, lastName, idNumber):
6+
self.firstName = firstName
7+
self.lastName = lastName
8+
self.idNumber = idNumber
9+
10+
def printPerson(self):
11+
print("Name:", self.lastName + ",", self.firstName)
12+
print("ID:", self.idNumber)
13+
14+
15+
# Child class inherits parent class
16+
class Student(Person):
17+
18+
def __init__(self, firstName, lastName, idNum, scores):
19+
super(Student, self).__init__(firstName, lastName, idNum)
20+
self.scores = scores
21+
22+
def calculate(self):
23+
# Compute mean score
24+
average_score = sum(self.scores) / len(self.scores)
25+
26+
# Assign grades according to the set rule
27+
if average_score >= 90 and average_score <= 100:
28+
return "O"
29+
elif average_score >= 80 and average_score < 90:
30+
return "E"
31+
elif average_score >= 70 and average_score < 80:
32+
return "A"
33+
elif average_score >= 55 and average_score < 70:
34+
return "P"
35+
elif average_score >= 40 and average_score < 55:
36+
return "D"
37+
else:
38+
return "T"
39+
40+
41+
if __name__ == "__main__":
42+
# Read input linear from stdin
43+
line = input().split()
44+
45+
# Get student details
46+
firstName = line[0]
47+
lastName = line[1]
48+
idNum = line[2]
49+
50+
# Read number of score integer from stdin
51+
numScores = int(input())
52+
53+
# Read scores integer from stdin
54+
scores = list(map(int, input().split()))
55+
56+
# Instantiat Student class
57+
student_object = Student(firstName, lastName, idNum, scores)
58+
59+
# Call member method to print details
60+
student_object.printPerson()
61+
62+
# Call member method to compute grade and print
63+
print("Grade:", student_object.calculate())

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