├── .gitattributes
├── .gitignore
├── Algorithms
├── 01. Warmup
│ ├── 001. Solve Me First.py
│ ├── 002. Simple Array Sum.py
│ ├── 003. Compare the Triplets.py
│ ├── 004. A Very Big Sum.py
│ ├── 005. Diagonal Difference.py
│ ├── 006. Plus Minus.py
│ ├── 007. Staircase.py
│ ├── 008. Mini-Max Sum.py
│ ├── 009. Birthday Cake Candles.py
│ └── 010. Time Conversion.py
├── 02. Implementation
│ ├── 001. Grading Students.py
│ ├── 002. Apple and Orange.py
│ ├── 003. Kangaroo.py
│ ├── 004. Between Two Sets.py
│ ├── 005. Breaking the Records.py
│ ├── 006. Birthday Chocolate.py
│ ├── 013. Electronics Shop.py
│ ├── 014. Cats and a Mouse.py
│ ├── 015. Forming a Magic Square.py
│ ├── 016. Picking Numbers.py
│ ├── 017. Climbing the Leaderboard.py
│ └── 018. The Hurdle Race.py
├── 04. Sorting
│ ├── 001. Intro to Tutorial Challenges.py
│ └── 002. Big Sorting.py
├── 05. Search
│ └── 007. Pairs.py
├── 07. Greedy
│ ├── 001. Minimum Absolute Difference in an Array.py
│ ├── 002. Marc's Cakewalk.py
│ └── 014. Permuting Two Arrays.py
└── 08. Dynamic Programming
│ ├── 001. The Coin Change Problem.py
│ ├── 002. Equal.py
│ ├── 003. Sherlock and Cost.py
│ ├── 004. Construct the Array.py
│ └── 008. Fibonacci Modified.py
├── Artificial Intelligence
└── Statistics and Machine Learning
│ └── 001. Laptop Battery Life.py
├── Automated readme generation.py
├── C++
└── 01. Introduction
│ ├── 001. Say Hello, World! With Cpp.cpp
│ └── CMakeLists.txt
├── Data Structures
└── 01. Arrays
│ └── 001. Arrays - DS.py
├── Interview Preparation Kit - CPP
├── 01. Warm-up Challenges
│ ├── 001. Sock Merchant.cpp
│ ├── 002. Counting Valleys.cpp
│ ├── 003. Jumping on the Clouds.cpp
│ ├── 004. Repeated String.cpp
│ └── CMakeLists.txt
├── 02. Arrays
│ ├── 001. 2D Array - DS.cpp
│ ├── 002. Arrays - Left Rotation.cpp
│ ├── 003. New Year Chaos.cpp
│ ├── 004. Minimum Swaps 2.cpp
│ ├── 005. Array Manipulation.cpp
│ └── CMakeLists.txt
├── 03. Dictionaries and Hashmaps
│ ├── 001. Hash Tables - Ransom Note.cpp
│ ├── 002. Two Strings.cpp
│ ├── 003. Sherlock and Anagrams.cpp
│ ├── 004. Count Triplets.cpp
│ ├── 005. Frequency Queries.cpp
│ └── CMakeLists.txt
├── 04. Sorting
│ ├── 003. Sorting - Comparator.cpp
│ ├── 004. Fraudulent Activity Notifications.cpp
│ └── CMakeLists.txt
├── 05. String Manipulation
│ ├── 001. Strings - Making Anagrams.cpp
│ ├── 002. Alternating Characters.cpp
│ ├── 003. Sherlock and the Valid String.cpp
│ ├── 004. Special String Again.cpp
│ ├── 005. Common Child.cpp
│ └── CMakeLists.txt
├── 06. Greedy Algorithms
│ ├── 001. Minimum Absolute Difference in an Array.cpp
│ ├── 002. Luck Balance.cpp
│ ├── 003. Greedy Florist.cpp
│ ├── 004. Max Min.cpp
│ └── CMakeLists.txt
├── 07. Search
│ ├── 001. Hash Tables Ice Cream Parlor.cpp
│ └── CMakeLists.txt
├── 08. Dynamic Programming
│ ├── 001. Max Array Sum.cpp
│ ├── 002. Abbreviation.cpp
│ ├── 003. Candies.cpp
│ └── CMakeLists.txt
├── 09. Stacks and Queues
│ ├── 001. Balanced Brackets.cpp
│ ├── 003. Largest Rectangle.cpp
│ └── CMakeLists.txt
├── 10. Graphs
│ ├── 003. BFS - Shortest Reach in a Graph.cpp
│ ├── 004. DFS - Connected Cell in a Grid.cpp
│ └── CMakeLists.txt
└── 11. Trees
│ ├── 001. Tree - Height of a Binary Tree.cpp
│ └── CMakeLists.txt
├── Interview Preparation Kit - Python
├── 01. Warm-up Challenges
│ ├── 001. Sock Merchant.py
│ ├── 002. Counting Valleys.py
│ ├── 003. Jumping on the Clouds.py
│ └── 004. Repeated String.py
├── 02. Arrays
│ ├── 001. Arrays - Left Rotation.py
│ ├── 002. 2D Array - DS.py
│ ├── 003. New Year Chaos.py
│ ├── 004. Minimum Swaps 2.py
│ └── 005. Array Manipulation.py
├── 03. Dictionaries and Hashmaps
│ ├── 001. Hash Tables - Ransom Note.py
│ ├── 002. Two Strings.py
│ ├── 003. Count Triplets.py
│ ├── 004. Frequency Queries.py
│ └── 005. Sherlock and Anagrams.py
├── 04. Sorting
│ ├── 001. Sorting - Bubble Sort.py
│ └── 002. Mark and Toys.py
├── 07. Search
│ ├── 001. Hash Tables - Ice Cream Parlor.py
│ ├── 002. Minimum Time Required.py
│ └── 003. Triple sum.py
└── 08. Dynamic Programming
│ └── 001. Max Array Sum.py
├── LICENSE
├── Python
├── 01. Introduction
│ ├── 001. Say Hello, World! With Python.py
│ ├── 002. Python If-Else.py
│ ├── 003. Arithmetic Operators.py
│ ├── 004. Python Division.py
│ ├── 005. Loops.py
│ ├── 006. Write a function.py
│ └── 007. Print Function.py
├── 02. Basic Data Types
│ ├── 001. List Comprehensions.py
│ ├── 002. Find the Runner-Up Score!.py
│ ├── 003. Nested Lists.py
│ ├── 004. Finding the percentage.py
│ ├── 005. Lists.py
│ └── 006. Tuples.py
├── 03. Strings
│ ├── 001. sWAP cASE.py
│ ├── 002. String Split and Join.py
│ ├── 003. What's Your Name.py
│ ├── 004. Mutations.py
│ ├── 005. Find a string.py
│ ├── 006. String Validators.py
│ ├── 007. Text Alignment.py
│ ├── 008. Text Wrap.py
│ ├── 009. Designer Door Mat.py
│ ├── 010. String Formatting.py
│ └── 011. Capitalize!.py
├── 04. Sets
│ ├── 001. Introduction to Sets.py
│ ├── 002. No Idea!.py
│ ├── 003. Symmetric Difference.py
│ ├── 004. Set add().py
│ ├── 005. Set discard() remove() pop().py
│ ├── 006. Set union() Operation.py
│ ├── 007. Set intersection() Operation.py
│ ├── 008. Set difference() Operation.py
│ ├── 009. Set symmetric_difference() Operation.py
│ ├── 010. Set Mutations.py
│ ├── 011. The Captain's Room.py
│ ├── 012. Check Subset.py
│ └── 013. Check Strict Superset.py
├── 06. Itertools
│ ├── 001. itertools.product().py
│ ├── 002. itertools.combinations().py
│ ├── 003. itertools.permutations().py
│ ├── 004. itertools.combinations_with_replacement().py
│ ├── 005. Compress the String!.py
│ ├── 006. Iterables and Iterators.py
│ └── 007. Maximize It!.py
├── 07. Collections
│ ├── 001. collections.Counter().py
│ ├── 002. DefaultDict Tutorial.py
│ ├── 003. Collections namedtuple().py
│ ├── 004. Collections OrderedDict().py
│ ├── 005. Word Order.py
│ ├── 006. Collections deque().py
│ ├── 007. Company Logo.py
│ └── 008. Piling Up!.py
├── 08. Date and Time
│ ├── 001. Calendar Module.py
│ └── 002. Time Delta.py
├── 09. Errors and Exceptions
│ ├── 001. Exceptions.py
│ └── 002. Incorrect Regex.py
└── 16. Numpy
│ ├── 001. Arrays.py
│ └── 002. Shape and Reshape.py
├── README.md
├── SQL
├── 01. Basic Select
│ ├── 001. Revising the Select Query I.sql
│ ├── 002. Revising the Select Query II.sql
│ ├── 003. Select All.sql
│ ├── 004. Select By ID.sql
│ ├── 005. Japanese Cities' Attributes.sql
│ ├── 006. Japanese Cities' Names.sql
│ ├── 007. Weather Observation Station 1.sql
│ ├── 008. Weather Observation Station 3.sql
│ ├── 009. Weather Observation Station 4.sql
│ ├── 010. Weather Observation Station 5.sql
│ ├── 011. Weather Observation Station 6.sql
│ ├── 012. Weather Observation Station 7.sql
│ ├── 013. Weather Observation Station 8.sql
│ ├── 014. Weather Observation Station 9.sql
│ ├── 015. Weather Observation Station 10.sql
│ ├── 016. Weather Observation Station 11.sql
│ ├── 017. Weather Observation Station 12.sql
│ ├── 018. Higher Than 75 Marks.sql
│ ├── 019. Employee Names.sql
│ └── 020. Employee Salaries.sql
├── 02. Advanced Select
│ ├── 001. Type of Triangle.sql
│ ├── 002. The PADS.sql
│ └── 004. Binary Tree Nodes.sql
├── 03. Aggregation
│ ├── 001. Revising Aggregations - The Count Function.sql
│ ├── 002. Revising Aggregations - The Sum Function.sql
│ ├── 003. Revising Aggregations - Averages.sql
│ ├── 004. Average Population.sql
│ ├── 005. Japan Population.sql
│ ├── 006. Population Density Difference.sql
│ ├── 007. The Blunder.sql
│ ├── 008. Top Earners.sql
│ ├── 009. Weather Observation Station 2.sql
│ ├── 010. Weather Observation Station 13.sql
│ ├── 011. Weather Observation Station 14.sql
│ ├── 012. Weather Observation Station 15.sql
│ ├── 013. Weather Observation Station 16.sql
│ ├── 014. Weather Observation Station 17.sql
│ ├── 015. Weather Observation Station 18.sql
│ ├── 016. Weather Observation Station 19.sql
│ └── 017. Weather Observation Station 20.sql
└── 04. Basic Join
│ ├── 001. Asian Population.sql
│ ├── 002. African Cities.sql
│ ├── 003. Average Population of Each Continent.sql
│ └── 004. The Report.sql
└── Tutorials
└── 01. 10 Days of Statistics
├── 001. Day 0 - Mean, Median, and Mode.py
├── 002. Day 0 - Weighted Mean.py
├── 003. Day 1 - Quartiles.py
├── 004. Day 1 - Interquartile Range.py
├── 005. Day 1 - Standard Deviation.py
├── 006. Day 4 - Binomial Distribution I.py
├── 007. Day 4 - Binomial Distribution II.py
├── 008. Day 4 - Geometric Distribution I.py
├── 009. Day 4 - Geometric Distribution II.py
├── 010. Day 5 - Poisson Distribution I.py
├── 011. Day 5 - Poisson Distribution II.py
├── 012. Day 5 - Normal Distribution I.py
├── 013. Day 5 - Normal Distribution II.py
├── 014. Day 6 - The Central Limit Theorem I.py
├── 015. Day 6 - The Central Limit Theorem II.py
└── 016. Day 6 - The Central Limit Theorem III.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 | /Interview Preparation Kit - CPP/01. Warm-up Challenges/cmake-build-debug/
3 | /Interview Preparation Kit - CPP/02. Arrays/cmake-build-debug/
4 | /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/cmake-build-debug/
5 | /Interview Preparation Kit - CPP/04. Sorting/cmake-build-debug/
6 | /Interview Preparation Kit - CPP/05. String Manipulation/cmake-build-debug/
7 | /Interview Preparation Kit - CPP/08. Dynamic Programming/cmake-build-debug/
8 | /Interview Preparation Kit - CPP/09. Stacks and Queues/cmake-build-debug/
9 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/001. Solve Me First.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/solve-me-first/problem
2 | # Score: 1
3 |
4 |
5 | a, b = int(input()), int(input())
6 | print(a + b)
7 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/002. Simple Array Sum.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/simple-array-sum/problem
2 | # Score: 10
3 |
4 |
5 | n = int(input())
6 | arr = list(map(int, input().split()))
7 | print(sum(arr))
8 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/003. Compare the Triplets.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/compare-the-triplets/problem
2 | # Score: 10
3 |
4 |
5 | a = list(map(int, input().split()))
6 | b = list(map(int, input().split()))
7 | aliceScore = sum([(1 if a[i] > b[i] else 0) for i in range(3)])
8 | bobScore = sum([(1 if a[i] < b[i] else 0) for i in range(3)])
9 | print(aliceScore, bobScore)
10 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/004. A Very Big Sum.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/a-very-big-sum/problem
2 | # Score: 10
3 |
4 |
5 | n = int(input())
6 | arr = list(map(int, input().split()))
7 | print(sum(arr))
8 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/005. Diagonal Difference.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/diagonal-difference/problem
2 | # Score: 10
3 |
4 |
5 | a = []
6 | result = 0
7 | for i in range(int(input())):
8 | a = list(map(int, input().split()))
9 | result += a[i] - a[- 1 - i]
10 | print(abs(result))
11 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/006. Plus Minus.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/plus-minus/problem
2 | # Score: 10
3 |
4 |
5 | n = int(input())
6 | arr = list(map(int, input().split()))
7 | print("{:.6f}".format(len([x for x in arr if x > 0]) / n))
8 | print("{:.6f}".format(len([x for x in arr if x < 0]) / n))
9 | print("{:.6f}".format(len([x for x in arr if x == 0]) / n))
10 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/007. Staircase.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/staircase/problem
2 | # Score: 10
3 |
4 |
5 | def staircase(a):
6 | for i in range(1, a + 1):
7 | print((a - i) * ' ' + i * "#")
8 |
9 |
10 | n = int(input())
11 | staircase(n)
12 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/008. Mini-Max Sum.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/mini-max-sum/problem
2 | # Score: 10
3 |
4 |
5 | arr = list(map(int, input().split()))
6 | print(sum(arr) - max(arr), sum(arr) - min(arr))
7 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/009. Birthday Cake Candles.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/birthday-cake-candles/problem
2 | # Score: 10
3 |
4 |
5 | n = int(input())
6 | ar = list(map(int, input().split()))
7 | print(ar.count(max(ar)))
8 |
--------------------------------------------------------------------------------
/Algorithms/01. Warmup/010. Time Conversion.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/time-conversion/problem
2 | # Score: 15
3 |
4 |
5 | import time
6 | print(time.strftime('%H:%M:%S', time.strptime(input(), '%I:%M:%S%p')))
7 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/001. Grading Students.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/grading/problem
2 | # Score: 10
3 |
4 |
5 | for _ in range(int(input())):
6 | grade = int(input())
7 | if grade >= 38 and grade % 5 >= 3:
8 | grade = (grade + 5) // 5 * 5
9 | print(grade)
10 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/002. Apple and Orange.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/apple-and-orange/problem
2 | # Score: 10
3 |
4 |
5 | s, t, a, b, m, n = map(int, input().split() + input().split() + input().split())
6 | apple = list(map(int, input().split()))
7 | orange = list(map(int, input().split()))
8 | print(sum(s <= a + i <= t for i in apple))
9 | print(sum(s <= b + i <= t for i in orange))
10 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/003. Kangaroo.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/kangaroo/problem
2 | # Score: 10
3 |
4 |
5 | def kangaroo(x1, v1, x2, v2):
6 | return 'YES' if (v1 > v2) and (x2 - x1) % (v2 - v1) == 0 else 'NO'
7 |
8 |
9 | x1, v1, x2, v2 = map(int, input().split())
10 | print(kangaroo(x1, v1, x2, v2))
11 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/004. Between Two Sets.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/between-two-sets/problem
2 | # Score: 10
3 |
4 |
5 | _, a, b = input(), list(map(int, input().split())), list(map(int, input().split()))
6 | print(sum([all(i % x == 0 for x in a) and
7 | all(x % i == 0 for x in b) for i in range(max(a), min(b)+1)]))
8 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/005. Breaking the Records.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
2 | # Score: 10
3 |
4 |
5 | def breaking_records(score):
6 | min = max = score[0]
7 | min_count = max_count = 0
8 | for i in score[1:]:
9 | if i > max:
10 | max_count += 1
11 | max = i
12 | if i < min:
13 | min_count += 1
14 | min = i
15 | return max_count, min_count
16 |
17 |
18 | n = int(input())
19 | score = list(map(int, input().split()))
20 | print(*breaking_records(score))
21 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/006. Birthday Chocolate.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/the-birthday-bar/problem
2 | # Score: 10
3 |
4 |
5 | n, s = int(input().strip()), list(map(int, input().split()))
6 | d, m = map(int, input().split())
7 | print(sum([sum(s[i: i + m]) == d for i in range(len(s) - m + 1)]))
8 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/013. Electronics Shop.py:
--------------------------------------------------------------------------------
1 | # Problem https://www.hackerrank.com/challenges/electronics-shop/problem
2 | # Score: 15
3 |
4 |
5 | def getMoneySpent(keyboards, drives, b):
6 | result = -1
7 | for i in range(1, len(keyboards)):
8 | for j in range(1, len(drives)):
9 | if result < keyboards[i] + drives[j] <= b:
10 | result = keyboards[i] + drives[j]
11 | return result
12 |
13 |
14 | b, n, m = map(int, input().split())
15 | keyboards = list(map(int, input().rstrip().split()))
16 | drives = list(map(int, input().rstrip().split()))
17 | moneySpent = getMoneySpent(keyboards, drives, b)
18 | print(moneySpent)
19 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/014. Cats and a Mouse.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/cats-and-a-mouse/problem
2 | # Score: 15
3 |
4 |
5 | def catAndMouse(catA, catB, mouseC):
6 | distanceA = abs(catA - mouseC)
7 | distanceB = abs(catB - mouseC)
8 | if distanceA > distanceB:
9 | print('Cat B')
10 | elif distanceA == distanceB:
11 | print('Mouse C')
12 | else:
13 | print('Cat A')
14 |
15 |
16 | n = int(input())
17 | for i in range(n):
18 | catA, catB, mouseC = map(int, input().split())
19 | catAndMouse(catA, catB, mouseC)
20 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/015. Forming a Magic Square.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/magic-square-forming
2 | # Score: 20
3 |
4 |
5 | def formingMagicSquare(square):
6 | allSquares = [
7 | [[4, 9, 2], [3, 5, 7], [8, 1, 6]],
8 | [[2, 7, 6], [9, 5, 1], [4, 3, 8]],
9 | [[6, 1, 8], [7, 5, 3], [2, 9, 4]],
10 | [[8, 3, 4], [1, 5, 9], [6, 7, 2]],
11 | [[2, 9, 4], [7, 5, 3], [6, 1, 8]],
12 | [[6, 7, 2], [1, 5, 9], [8, 3, 4]],
13 | [[8, 1, 6], [3, 5, 7], [4, 9, 2]],
14 | [[4, 3, 8], [9, 5, 1], [2, 7, 6]],
15 | ]
16 | minCost = 9 * 9
17 | for magicSquare in allSquares:
18 | cost = 0
19 | for i in range(3):
20 | for j in range(3):
21 | cost += abs(magicSquare[i][j] - square[i][j])
22 | if cost < minCost:
23 | minCost = cost
24 | return minCost
25 |
26 |
27 | square = [
28 | list(map(int, input().split())),
29 | list(map(int, input().split())),
30 | list(map(int, input().split()))
31 | ]
32 | print(formingMagicSquare(square))
33 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/016. Picking Numbers.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/picking-numbers
2 | # Score: 20
3 |
4 |
5 | def pickingNumbers(arr):
6 | result = 0
7 | checked = set()
8 | for i in range(len(arr)):
9 | if i not in checked:
10 | maxCount = max(arr.count(arr[i]) + arr.count(arr[i] + 1), arr.count(arr[i]) + arr.count(arr[i] - 1))
11 | if maxCount > result:
12 | result = maxCount
13 | checked.add(i)
14 | return result
15 |
16 |
17 | n = int(input().strip())
18 | arr = list(map(int, input().strip().split(' ')))
19 | result = pickingNumbers(arr)
20 | print(result)
21 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/017. Climbing the Leaderboard.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem
2 | # Score: 20
3 |
4 |
5 | def climbingLeaderboard(leaderboard, aliceScores):
6 | rankings = createRankings(leaderboard)
7 | i = len(leaderboard) - 1
8 | for score in aliceScores:
9 | flag = True
10 | while flag:
11 | if i == -1:
12 | print(1)
13 | flag = False
14 | elif score < leaderboard[i]:
15 | print(rankings[i] + 1)
16 | flag = False
17 | elif score == leaderboard[i]:
18 | print(rankings[i])
19 | flag = False
20 | elif score > leaderboard[i]:
21 | i -= 1
22 | return
23 |
24 |
25 | def createRankings(leaderboard):
26 | rankings = [1]
27 | rank = 1
28 | for i in range(1, len(leaderboard)):
29 | if leaderboard[i] < leaderboard[i - 1]:
30 | rank += 1
31 | rankings.append(rank)
32 | return rankings
33 |
34 |
35 | lenOfLeaderboard = int(input())
36 | leaderboard = list(map(int, input().rstrip().split()))
37 | lenOfAliceScores = int(input())
38 | aliceScores = list(map(int, input().rstrip().split()))
39 | climbingLeaderboard(leaderboard, aliceScores)
40 |
--------------------------------------------------------------------------------
/Algorithms/02. Implementation/018. The Hurdle Race.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/the-hurdle-race/problem
2 | # Score: 15
3 |
4 |
5 | n, k = map(int, input().split())
6 | hurdles = list(map(int, input().split()))
7 | numberOfPotions = max(0, max(hurdles) - k)
8 | print(numberOfPotions)
9 |
--------------------------------------------------------------------------------
/Algorithms/04. Sorting/001. Intro to Tutorial Challenges.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/tutorial-intro/problem
2 | # Score: 30
3 |
4 |
5 | v = int(input())
6 | n = int(input())
7 | arr = list(map(int, input().split()))
8 | i = 0
9 | while arr[i] != v:
10 | i += 1
11 | print(i)
12 |
--------------------------------------------------------------------------------
/Algorithms/04. Sorting/002. Big Sorting.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/big-sorting/problem
2 | # Score: 20
3 |
4 |
5 | n = int(input())
6 | arr = []
7 | for i in range(n):
8 | arr.append(input())
9 | arr.sort(key=int)
10 | for _ in arr:
11 | print(_)
12 |
--------------------------------------------------------------------------------
/Algorithms/05. Search/007. Pairs.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/pairs/problem
2 | # Score: 50
3 |
4 |
5 | # use two-pointers approach on a sorted array
6 | n, value = map(int, input().split())
7 | points = sorted(list(map(int, input().split())))
8 |
9 | ans = 0
10 | i = 0
11 | j = 1
12 |
13 | while j < n:
14 | if points[j] - points[i] == value:
15 | ans += 1
16 | j += 1
17 | elif points[j] - points[i] > value:
18 | i += 1
19 | elif points[j] - points[i] < value:
20 | j += 1
21 |
22 | print(ans)
23 |
--------------------------------------------------------------------------------
/Algorithms/07. Greedy/001. Minimum Absolute Difference in an Array.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem
2 | # Score: 15
3 |
4 |
5 | _ = input()
6 | arr = sorted(map(int, input().split()))
7 | diff = 2*10**9
8 | for i in range(1, len(arr)):
9 | diff = min(diff, arr[i] - arr[i-1])
10 | print(diff)
11 |
--------------------------------------------------------------------------------
/Algorithms/07. Greedy/002. Marc's Cakewalk.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/marcs-cakewalk/problem
2 | # Score: 15
3 |
4 |
5 | _ = input()
6 | calories = list(map(int, input().split()))
7 | calories = sorted(calories, reverse=True)
8 | ans = 0
9 | for index, cupcake in enumerate(calories):
10 | ans += 2**index*cupcake
11 | print(ans)
12 |
--------------------------------------------------------------------------------
/Algorithms/07. Greedy/014. Permuting Two Arrays.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/two-arrays/problem
2 | # Score: 40
3 |
4 |
5 | n = int(input())
6 | for _ in range(n):
7 | __, k = map(int, input().split())
8 | a = sorted(list(map(int, input().split())))
9 | b = sorted(list(map(int, input().split())), reverse=True)
10 | if all([a[i] + b[i] >= k for i in range(len(a))]):
11 | print('YES')
12 | else:
13 | print('NO')
14 |
--------------------------------------------------------------------------------
/Algorithms/08. Dynamic Programming/001. The Coin Change Problem.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/coin-change/problem
2 | # Score: 60
3 |
4 |
5 | n, m = map(int, input().split())
6 | coins = list(map(int, input().split()))
7 | ans = [1] + [0] * n
8 | for i in range(m):
9 | for j in range(coins[i], n + 1):
10 | ans[j] += ans[j - coins[i]]
11 | print(ans[-1])
12 |
--------------------------------------------------------------------------------
/Algorithms/08. Dynamic Programming/002. Equal.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/equal/problem
2 | # Score: 30
3 |
4 | # the idea here is that we can go not just to minimum element in array,
5 | # but also to min+1 and min+2
6 | target = [0, 1, 2]
7 |
8 |
9 | def solution(arr):
10 | min_arr = min(arr)
11 | results = [0] * len(target) # array for results with each target
12 | for item in arr:
13 | for i in target:
14 | gap = item - min_arr + i
15 | results[i] += gap // 5 + (gap%5) // 2 + (gap%5)%2
16 | return min(results)
17 |
18 |
19 | for t in range(int(input())):
20 | input()
21 | items = list(map(int, input().split()))
22 | print(solution(items))
23 |
--------------------------------------------------------------------------------
/Algorithms/08. Dynamic Programming/003. Sherlock and Cost.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/sherlock-and-cost/problem
2 | # Score: 50
3 |
4 |
5 | test = int(input())
6 | for i in range(test):
7 | n = int(input())
8 | b = list(map(int, input().split()))
9 |
10 | dp = [[0], [0]]
11 |
12 | for i in range(1, len(b)):
13 | add_1 = max(dp[0][-1], dp[1][-1] + b[i - 1] - 1)
14 | add_max = max(dp[0][-1] + b[i] - 1, dp[1][-1] + abs(b[i] - b[i - 1]))
15 | dp[0].append(add_1)
16 | dp[1].append(add_max)
17 |
18 | print(max(dp[0][-1], dp[1][-1]))
19 |
--------------------------------------------------------------------------------
/Algorithms/08. Dynamic Programming/004. Construct the Array.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/construct-the-array/problem
2 | # Score: 35
3 |
4 |
5 | def count_array(n, k, x):
6 | dp = [[1], [1]]
7 | if x == 1:
8 | dp = [[1], [0]]
9 | else:
10 | dp = [[1], [1]]
11 |
12 | for x in range(n - 2):
13 | dp[0].append(dp[0][-1] * (k - 1) % (10 ** 9 + 7))
14 | dp[1].append((dp[0][-1] - dp[1][-1]) % (10 ** 9 + 7))
15 | return dp[1][-1]
16 |
17 |
18 | n, k, x = map(int, input().split())
19 | print(count_array(n, k, x))
20 |
--------------------------------------------------------------------------------
/Algorithms/08. Dynamic Programming/008. Fibonacci Modified.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/fibonacci-modified/problem
2 | # Score: 45
3 |
4 |
5 | n1, n2, n = map(int, input().split())
6 | sequence = [n1, n2]
7 | if n <= 2:
8 | print(sequence[n-1])
9 | else:
10 | for i in range(n-2):
11 | sequence.append(sequence[-2] + sequence[-1]**2)
12 | print(sequence[-1])
13 |
--------------------------------------------------------------------------------
/Artificial Intelligence/Statistics and Machine Learning/001. Laptop Battery Life.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/battery/problem
2 | # Score: 10
3 |
4 |
5 | import pandas as pd
6 | from sklearn.linear_model import LinearRegression
7 |
8 |
9 | timeCharged = float(input())
10 | data = pd.read_csv('trainingdata.txt', names=['charged', 'lasted'])
11 | train = data[data['lasted'] < 8]
12 | model = LinearRegression()
13 | model.fit(train['charged'].values.reshape(-1, 1), train['lasted'].values.reshape(-1, 1))
14 | ans = model.predict([[timeCharged]])
15 | print(min(ans[0][0], 8))
16 |
--------------------------------------------------------------------------------
/Automated readme generation.py:
--------------------------------------------------------------------------------
1 | import os
2 | import functools
3 |
4 |
5 | def getFoldersNames(path):
6 | folders = []
7 | for item in os.listdir(path):
8 | if not os.path.isfile(item) and item not in ('.git', '.idea'):
9 | folders.append(item)
10 | return folders
11 |
12 |
13 | def getFilesNames(path):
14 | files = os.listdir(path)
15 | return files
16 |
17 |
18 | def getProblemURLandScore(path):
19 | inFile = open(path, 'r', encoding='utf-8')
20 | url = inFile.readline().split()[-1]
21 | score = inFile.readline().split()[-1]
22 | inFile.close()
23 | return url, score
24 |
25 |
26 | def getTotalNumberOfProblems():
27 | totalNumber = 0
28 | folders = getFoldersNames(os.getcwd())
29 | for folder in folders:
30 | subfolders = getFoldersNames(os.path.join(os.getcwd(), folder))
31 | for subfolder in subfolders:
32 | totalNumber += len(getFilesNames(os.path.join(os.getcwd(), folder, subfolder)))
33 | return totalNumber
34 |
35 |
36 | readmeFile = open('README.md', 'w', encoding='utf-8')
37 | print('

', file=readmeFile)
38 | print(file=readmeFile)
39 | print('# Solutions to Hackerrank practice problems', file=readmeFile)
40 | print('This repository contains ' + str(getTotalNumberOfProblems()) + ' solutions to Hackerrank practice problems with Python 3, C++ and Oracle SQL.', file=readmeFile)
41 | print(file=readmeFile)
42 | print('Updated daily :) If it was helpful please press a star.', file=readmeFile)
43 | print(file=readmeFile)
44 | print('[](https://github.com/marinskiy/HackerrankPractice) ', file=readmeFile)
45 | print('[](https://github.com/marinskiy/HackerrankPractice)', file=readmeFile)
46 | print('[](https://github.com/marinskiy/HackerrankPractice) ', file=readmeFile)
47 | print('[](https://github.com/marinskiy/HackerrankPractice)', file=readmeFile)
48 | print(file=readmeFile)
49 |
50 | folders = getFoldersNames(os.getcwd())
51 | for folder in sorted(folders):
52 | print('- ' + folder, file=readmeFile)
53 | subfolders = getFoldersNames(os.path.join(os.getcwd(), folder))
54 | for subfolder in sorted(subfolders):
55 | print(' ' + subfolder, file=readmeFile)
56 | files = getFilesNames(os.path.join(os.getcwd(), folder, subfolder))
57 | for file in sorted(files):
58 | if file.endswith(('.cpp', '.py', '.sql')):
59 | url, score = getProblemURLandScore(os.path.join(os.getcwd(), folder, subfolder, file))
60 | print(' - ' + "".join(file.split(".")[1:-1])[1:]
61 | + ' | [Problem](' + url
62 | + ')'
63 | + ' | [Solution]'
64 | + '(https://github.com/marinskiy/HackerrankPractice/blob/master/'
65 | + folder.replace(' ', '%20') + '/' + subfolder.replace(' ', '%20') + '/'
66 | + file.replace(' ', '%20') + ')'
67 | + ' | Score: ' + str(score), file=readmeFile)
68 |
69 | readmeFile.close()
70 |
--------------------------------------------------------------------------------
/C++/01. Introduction/001. Say Hello, World! With Cpp.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/cpp-hello-world/problem
2 | // Score: 10
3 |
4 |
5 | #include
6 |
7 | int main() {
8 | std::cout << "Hello, World!";
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/C++/01. Introduction/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 3.8)
2 |
3 | project(introduction)
4 |
5 | add_executable(task-1 "001. Say Hello, World! With Cpp.cpp")
6 |
--------------------------------------------------------------------------------
/Data Structures/01. Arrays/001. Arrays - DS.py:
--------------------------------------------------------------------------------
1 | # Problem: https://www.hackerrank.com/challenges/arrays-ds/problem
2 | # Score: 10
3 |
4 |
5 | def reverseArray(arr):
6 | result = arr[::-1]
7 | return result
8 |
9 |
10 | arrСount = int(input())
11 | arr = list(map(int, input().rstrip().split()))
12 | result = reverseArray(arr)
13 | print(*result)
14 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/01. Warm-up Challenges/001. Sock Merchant.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/sock-merchant/problem
2 | // Score: 10
3 |
4 |
5 | #include
6 |
7 |
8 | int main() {
9 | int n, element;
10 | int arr[101] = {0};
11 | int ans = 0;
12 |
13 | std::cin >> n;
14 |
15 | for (int i = 0; i < n; i++) {
16 | std::cin >> element;
17 | arr[element]++;
18 |
19 | ans += arr[element] / 2;
20 | arr[element] = arr[element] % 2;
21 | }
22 |
23 | std::cout << ans << std::endl;
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/01. Warm-up Challenges/002. Counting Valleys.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/counting-valleys/problem
2 | // Score: 15
3 |
4 | #include
5 | #include
6 | using namespace std;
7 |
8 | int main() {
9 | int n;
10 | cin >> n;
11 |
12 | string str;
13 | cin >> str;
14 |
15 | int ans = 0;
16 |
17 | int current_level = 0;
18 |
19 | for (char c: str){
20 | if (c == 'D') {
21 | if (current_level == 0){
22 | ans++;
23 | }
24 |
25 | current_level--;
26 | }
27 |
28 | else if (c == 'U') current_level++;
29 | }
30 |
31 | cout << ans;
32 |
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/01. Warm-up Challenges/003. Jumping on the Clouds.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem
2 | // Score: 20
3 |
4 |
5 | #include
6 | #include
7 | using namespace std;
8 |
9 | int main(){
10 | int n;
11 | cin >> n;
12 |
13 | int element;
14 | vector arr;
15 |
16 | while (cin >> element){
17 | arr.push_back(element);
18 | }
19 |
20 | int ans = 0;
21 | int position = 0;
22 |
23 | while (position < n - 1){
24 | position ++;
25 | if (position + 1 <= n - 1 && arr[position + 1] != 1){
26 | position ++;
27 | }
28 | ans ++;
29 | }
30 |
31 | cout << ans;
32 |
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/01. Warm-up Challenges/004. Repeated String.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/repeated-string/problem
2 | // Score: 20
3 |
4 |
5 | #include
6 | #include
7 |
8 | using namespace std;
9 |
10 |
11 | long long count(string const & str){
12 | long long ans = 0;
13 | for (const char & c: str){
14 | ans += c == 'a';
15 | }
16 | return ans;
17 | }
18 |
19 |
20 | int main(){
21 | string str;
22 | cin >> str;
23 |
24 | long long n;
25 | cin >> n;
26 |
27 | long long ans = 0;
28 | ans = n / str.size() * count(str) + count(str.substr(0, n % str.size()));
29 |
30 | cout << ans;
31 | return 0;
32 | }
33 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/01. Warm-up Challenges/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 3.8)
2 |
3 | project(warm-up)
4 |
5 | add_executable(task-1 "001. Sock Merchant.cpp")
6 | add_executable(task-2 "002. Counting Valleys.cpp")
7 | add_executable(task-3 "003. Jumping on the Clouds.cpp")
8 | add_executable(task-4 "004. Repeated String.cpp")
9 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/001. 2D Array - DS.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/2d-array/problem
2 | // Score: 15
3 |
4 |
5 | #include
6 | using namespace std;
7 |
8 | int hourglass_sum(int arr[6][6], int i, int j){
9 | int ans = 0;
10 | ans = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] +
11 | arr[i + 1][j + 1] +
12 | arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2];
13 | return ans;
14 | }
15 |
16 |
17 | int main(){
18 |
19 | int arr[6][6];
20 |
21 | for (auto & i : arr){
22 | for (int & j : i){
23 | cin >> j;
24 | }
25 | }
26 |
27 | int ans = -1000;
28 | for (int i = 0; i < 4; i++){
29 | for (int j = 0; j < 4; j++){
30 | if (hourglass_sum(arr, i, j) > ans){
31 | ans = hourglass_sum(arr, i, j);
32 | }
33 | }
34 | }
35 |
36 | cout << ans;
37 | return 0;
38 | }
39 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/002. Arrays - Left Rotation.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem
2 | // Score: 20
3 |
4 |
5 | #include
6 | #include
7 | using namespace std;
8 |
9 | int main(){
10 | int n, d;
11 |
12 | cin >> n;
13 | cin >> d;
14 |
15 | vector arr;
16 | for (int i = 0; i < n; i++){
17 | int tmp;
18 | cin >> tmp;
19 | arr.push_back(tmp);
20 | }
21 |
22 | for (int i = 0; i < n; i++){
23 | cout << arr[(i + d) % n] << " ";
24 | }
25 |
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/003. New Year Chaos.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/new-year-chaos/problem
2 | // Score: 40
3 |
4 | #include
5 | #include
6 | using namespace std;
7 |
8 |
9 | bool check_sorted(vector & arr){
10 | bool ans = true;
11 | for (int i = 0; i < arr.size() - 1; i++){
12 | if (arr[i] > arr[i + 1]){
13 | ans = false;
14 | }
15 | }
16 | return ans;
17 | }
18 |
19 |
20 | int main(){
21 | int t;
22 | cin >> t;
23 |
24 | for (int i = 0; i < t; i++){
25 | int n;
26 | cin >> n;
27 | vector arr;
28 |
29 | for (int j = 0; j < n; j++){
30 | int tmp;
31 | cin >> tmp;
32 | arr.push_back(tmp);
33 | }
34 |
35 | int ans = 0;
36 |
37 | for (int j = 0; j < 2; j++){
38 | for (int k = arr.size() - 1; k > 0; k--){
39 | if (arr[k] < arr[k - 1]){
40 | swap(arr[k], arr[k - 1]);
41 | ans++;
42 | }
43 | }
44 | }
45 |
46 | if (check_sorted(arr)){
47 | cout << ans << endl;
48 | }
49 | else {
50 | cout << "Too chaotic" << endl;
51 | }
52 |
53 | }
54 |
55 | return 0;
56 | }
57 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/004. Minimum Swaps 2.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/minimum-swaps-2/problem
2 | // Score: 40
3 |
4 |
5 | #include
6 | #include
7 | using namespace std;
8 |
9 |
10 | int main(){
11 | int n;
12 | cin >> n;
13 | vector arr;
14 |
15 | for (int i = 0; i < n; i++){
16 | int tmp;
17 | cin >> tmp;
18 | arr.push_back(tmp - 1);
19 | }
20 |
21 | int i = 0;
22 | int ans = 0;
23 | while (i < n){
24 | if (arr[i] != i){
25 | swap(arr[i], arr[arr[i]]);
26 | ans++;
27 | }
28 | else{
29 | i++;
30 | }
31 | }
32 |
33 | cout << ans;
34 |
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/005. Array Manipulation.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/crush/problem
2 | // Score: 60
3 |
4 |
5 | #include
6 | #include
7 | using namespace std;
8 |
9 |
10 | int main(){
11 | int n, m;
12 | cin >> n >> m;
13 |
14 | vector arr(n, 0);
15 |
16 | for (int i = 0; i < m; i++){
17 | int start, finish, value;
18 | cin >> start >> finish >> value;
19 | arr[start - 1] += value;
20 | arr[finish] -= value;
21 | }
22 |
23 | long long int ans = 0;
24 | long long int current = 0;
25 |
26 | for (int value: arr){
27 | current += value;
28 | if (current > ans){
29 | ans = current;
30 | }
31 | }
32 |
33 | cout << ans;
34 |
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/02. Arrays/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 3.8)
2 |
3 | project(arrays)
4 |
5 | add_executable(task-1 001.\ 2D\ Array\ -\ DS.cpp)
6 | add_executable(task-2 002.\ Arrays\ -\ Left\ Rotation.cpp)
7 | add_executable(task-3 003.\ New\ Year\ Chaos.cpp)
8 | add_executable(task-4 004.\ Minimum\ Swaps\ 2.cpp)
9 | add_executable(task-5 005.\ Array\ Manipulation.cpp)
10 |
--------------------------------------------------------------------------------
/Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/001. Hash Tables - Ransom Note.cpp:
--------------------------------------------------------------------------------
1 | // Problem: https://www.hackerrank.com/challenges/ctci-ransom-note/problem
2 | // Score: 25
3 |
4 | #include
5 | #include
6 | #include