Skip to content

Commit 173f01e

Browse files
committed
feat: Added solutions to the first 5 challenges
* Added solutions to the first 5 challenges from 3 Months Preparation Kit
1 parent 9f96f65 commit 173f01e

File tree

5 files changed

+219
-0
lines changed

5 files changed

+219
-0
lines changed
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 'breakingRecords' function below.
11+
#
12+
# The function is expected to return an INTEGER_ARRAY.
13+
# The function accepts INTEGER_ARRAY scores as parameter.
14+
#
15+
16+
17+
def breakingRecords(scores):
18+
minNumber = maxNumber = scores[0]
19+
minBreaking = maxBreaking = 0
20+
21+
for score in scores[1:]:
22+
if score < minNumber:
23+
minNumber = score
24+
minBreaking += 1
25+
26+
elif score > maxNumber:
27+
maxNumber = score
28+
maxBreaking += 1
29+
30+
return [maxBreaking, minBreaking]
31+
32+
33+
if __name__ == "__main__":
34+
fptr = open(os.environ["OUTPUT_PATH"], "w")
35+
36+
n = int(input().strip())
37+
38+
scores = list(map(int, input().rstrip().split()))
39+
40+
result = breakingRecords(scores)
41+
42+
fptr.write(" ".join(map(str, result)))
43+
fptr.write("\n")
44+
45+
fptr.close()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
public static String setFirstUpperCase(String word)
6+
{
7+
return Character.toUpperCase(word.charAt(0))+ word.substring(1);
8+
}
9+
10+
public static void main(String[] args) {
11+
Scanner scanner= new Scanner(System.in);
12+
boolean isSplit;
13+
Character SPLIT='S', CLASS='C', VARIABLE='V', METHOD='M',typeWord;
14+
15+
while(scanner.hasNext()){
16+
String[] line=scanner.nextLine().split(";");
17+
isSplit=SPLIT.equals(line[0].charAt(0));
18+
typeWord=line[1].charAt(0);
19+
String formattedStr="";
20+
String[] words = line[2].split(" ");
21+
22+
if(!isSplit){
23+
if(typeWord.equals(CLASS))
24+
for(String word: words)
25+
formattedStr+=setFirstUpperCase(word);
26+
27+
else{
28+
int counter=0;
29+
30+
for(String word:words){
31+
if(counter!=0)
32+
formattedStr+=setFirstUpperCase(word);
33+
else
34+
formattedStr+=word;
35+
36+
counter++;
37+
}
38+
39+
if(typeWord.equals(METHOD))
40+
formattedStr+="()";
41+
}
42+
}
43+
else{
44+
int counter=0;
45+
String word=words[0];
46+
47+
if(typeWord.equals(METHOD))
48+
word=word.substring(0, word.length()-2);
49+
50+
for(int i=0;i<word.length();i++){
51+
char letter=word.charAt(i);
52+
53+
if(counter!=0 && Character.isUpperCase(letter))
54+
formattedStr+=' ';
55+
56+
formattedStr+=Character.toLowerCase(letter);
57+
counter++;
58+
}
59+
}
60+
System.out.println(formattedStr);
61+
}
62+
}
63+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'miniMaxSum' function below.
11+
#
12+
# The function accepts INTEGER_ARRAY arr as parameter.
13+
#
14+
15+
def miniMaxSum(arr):
16+
minNumber=arr[0]
17+
maxNumber=arr[0]
18+
total=0
19+
20+
for number in arr:
21+
if number<minNumber:
22+
minNumber=number
23+
elif number>maxNumber:
24+
maxNumber=number
25+
26+
total+=number
27+
28+
print(f'{total-maxNumber} {total-minNumber}')
29+
30+
if __name__ == '__main__':
31+
32+
arr = list(map(int, input().rstrip().split()))
33+
34+
miniMaxSum(arr)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'plusMinus' function below.
11+
#
12+
# The function accepts INTEGER_ARRAY arr as parameter.
13+
#
14+
15+
def plusMinus(arr):
16+
numberLength=len(arr)
17+
positiveCounter=0
18+
negativeCounter=0
19+
ceroCounter=0
20+
21+
for number in arr:
22+
if number>0:
23+
positiveCounter+=1
24+
elif number<0:
25+
negativeCounter+=1
26+
else:
27+
ceroCounter+=1
28+
29+
for number in [positiveCounter, negativeCounter, ceroCounter]:
30+
print(number/numberLength)
31+
32+
if __name__ == '__main__':
33+
n = int(input().strip())
34+
35+
arr = list(map(int, input().rstrip().split()))
36+
37+
plusMinus(arr)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'timeConversion' function below.
11+
#
12+
# The function is expected to return a STRING.
13+
# The function accepts STRING s as parameter.
14+
#
15+
16+
17+
def timeConversion(s):
18+
hourFormat = s[-2:]
19+
militaryHour = int(s[:2])
20+
21+
if hourFormat == "AM":
22+
if militaryHour >= 12:
23+
militaryHour -= 12
24+
25+
elif militaryHour < 12:
26+
militaryHour += 12
27+
28+
return f"{militaryHour:02}{s[2:-2]}"
29+
30+
31+
if __name__ == "__main__":
32+
fptr = open(os.environ["OUTPUT_PATH"], "w")
33+
34+
s = input()
35+
36+
result = timeConversion(s)
37+
38+
fptr.write(result + "\n")
39+
40+
fptr.close()

0 commit comments

Comments
 (0)