Skip to content

Commit 694af3a

Browse files
author
abregman
committed
Copy questions from devops-exercisese to this repo
1 parent c336bd8 commit 694af3a

File tree

11 files changed

+1809
-2
lines changed

11 files changed

+1809
-2
lines changed

README.md

Lines changed: 1647 additions & 2 deletions
Large diffs are not rendered by default.

exercises/count_substring/exercise.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Count Substring
2+
3+
## Objectives
4+
5+
In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
6+
7+
NOTE: String letters are case-sensitive.
8+
9+
Sample Input
10+
11+
ABCDCDC
12+
CDC
13+
14+
Sample Output
15+
16+
2
17+
18+
## Solution
19+
20+
Click [here](solution.py) to view the solution

exercises/count_substring/solution.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
def count_substring(string, sub_string):
5+
count = 0
6+
for i in range(len(string)):
7+
if string[i:].startswith(sub_string):
8+
count += 1
9+
return count
10+
11+
if __name__ == '__main__':
12+
string = input().strip()
13+
sub_string = input().strip()
14+
15+
count = count_substring(string, sub_string)
16+
print(count)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Find the Runner-Up Score! (HackerRank Challenge)
2+
3+
The following challenge is from [HackerRank](https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem)
4+
5+
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.
6+
7+
Input Format
8+
9+
The first line contains . The second line contains an array of integers each separated by a space.
10+
11+
Constraints
12+
13+
Output Format
14+
15+
Print the runner-up score.
16+
17+
Sample Input 0
18+
19+
5
20+
2 3 6 6 5
21+
22+
Sample Output 0
23+
24+
5
25+
26+
## Solution
27+
28+
Click [here](solution.py) to view the solution.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
if __name__ == '__main__':
5+
n = int(input())
6+
arr = map(int, input().split())
7+
8+
# remove duplicates
9+
arr = list(dict.fromkeys(arr))
10+
# sort
11+
arr.sort()
12+
13+
print(arr[-2])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Nested Lists - HackerRank
2+
3+
Note: This question is from [HackerRank](https://www.hackerrank.com/challenges/nested-list/problem)
4+
5+
Given the names and grades for each student in a class of students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
6+
7+
Sample Input 0
8+
9+
5
10+
Harry
11+
37.21
12+
Berry
13+
37.21
14+
Tina
15+
37.2
16+
Akriti
17+
41
18+
Harsh
19+
39
20+
21+
Sample Output 0
22+
23+
Berry
24+
Harry
25+
26+
## Solution
27+
28+
Click [here](solution.py) to view the solution.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
scores_stats = []
5+
6+
for _ in range(0,int(input())):
7+
scores_stats.append([input(), float(input())])
8+
9+
# Make a unique list of score, sort it and get the lowest second score
10+
second_lowest = sorted(list(set([score for name, score in scores_stats])))[1]
11+
12+
# Iterate over the list of scores and names and print every match to the
13+
# lowest score we got above
14+
print('\n'.join([a for a,b in sorted(scores_stats) if b == second_lowest]))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Remove Duplicates
2+
3+
Note: this question is taken from [LeetCode](https://leetcode.com)
4+
5+
## Objectives
6+
7+
Given an integer list nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+

exercises/swap_case/exercise.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Swap Case - HackerRank
2+
3+
## Objectives
4+
5+
You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
6+
7+
For Example:
8+
9+
```
10+
Www.HackerRank.com → wWW.hACKERrANK.COM
11+
Pythonist 2 → pYTHONIST 2
12+
```
13+
14+
## Solution
15+
16+
Click [here](solution.py) to view the solution

exercises/swap_case/solution.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
def swap_case(s):
5+
string = ""
6+
for c in s:
7+
if c == c.upper():
8+
string += c.lower()
9+
else:
10+
string += c.upper()
11+
return string
12+
13+
if __name__ == '__main__':
14+
s = input()
15+
result = swap_case(s)
16+
print(result)

0 commit comments

Comments
 (0)