├── .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('[![GitHub last commit](https://img.shields.io/github/last-commit/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) ', file=readmeFile) 45 | print('[![GitHub commit activity the past week, 4 weeks, year](https://img.shields.io/github/commit-activity/y/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice)', file=readmeFile) 46 | print('[![GitHub repo size in bytes](https://img.shields.io/github/repo-size/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) ', file=readmeFile) 47 | print('[![GitHub stars](https://img.shields.io/github/stars/marinskiy/HackerrankPractice.svg)](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 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int m, n; 12 | cin >> m >> n; 13 | 14 | map magazine; 15 | 16 | for (int i = 0; i < m; i++) { 17 | string word; 18 | cin >> word; 19 | 20 | if (magazine.find(word) == magazine.end()){ 21 | magazine[word] = 1; 22 | } 23 | else { 24 | magazine[word]++; 25 | } 26 | } 27 | 28 | 29 | bool ans = true; 30 | for (int i = 0; i < n; i++){ 31 | string word; 32 | cin >> word; 33 | 34 | if (magazine.find(word) == magazine.end() || magazine[word] == 0){ 35 | ans = false; 36 | break; 37 | } 38 | else { 39 | magazine[word]--; 40 | } 41 | } 42 | 43 | 44 | if (ans) cout << "Yes" << endl; 45 | else cout << "No" << endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/002. Two Strings.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/two-strings/problem 2 | // Score: 25 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int p; 13 | cin >> p; 14 | 15 | for (int i = 0; i < p; i++){ 16 | string s1, s2; 17 | cin >> s1 >> s2; 18 | 19 | set letters; 20 | 21 | for (char c: s1){ 22 | letters.insert(c); 23 | } 24 | 25 | bool ans = false; 26 | for (char c: s2){ 27 | if (letters.find(c) != letters.end()){ 28 | ans = true; 29 | break; 30 | } 31 | } 32 | 33 | if (ans) cout << "YES" << endl; 34 | else cout << "NO" << endl; 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/003. Sherlock and Anagrams.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem 2 | // Score: 50 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | 12 | int main(){ 13 | int n; 14 | cin >> n; 15 | for (int t = 0; t < n; t++){ 16 | string str; 17 | cin >> str; 18 | 19 | map lib; 20 | 21 | for (int i = 1; i < str.size(); i++){ 22 | for (int j = 0; j < str.size() - i + 1; j++){ 23 | string tmp = str.substr(j, i); 24 | sort(tmp.begin(), tmp.end()); 25 | 26 | if (lib.find(tmp) != lib.end()){ 27 | lib[tmp]++; 28 | } 29 | else { 30 | lib[tmp] = 1; 31 | } 32 | 33 | } 34 | } 35 | 36 | int ans = 0; 37 | for (auto const & el: lib){ 38 | ans += el.second * (el.second - 1) / 2; 39 | } 40 | 41 | cout << ans << endl; 42 | } 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/004. Count Triplets.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/count-triplets-1/problem 2 | // Score: 25 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | struct custom_int{ 11 | long long int value = 0; 12 | }; 13 | 14 | 15 | int main(){ 16 | int n, r; 17 | cin >> n >> r; 18 | map arr2; 19 | map arr3; 20 | 21 | long long int ans = 0; 22 | 23 | for (int i = 0; i < n; i++) { 24 | int tmp; 25 | cin >> tmp; 26 | 27 | ans += arr3[tmp].value; 28 | arr3[tmp * r].value += arr2[tmp].value; 29 | arr2[tmp * r].value++; 30 | } 31 | 32 | cout << ans; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/005. Frequency Queries.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/frequency-queries/problem 2 | // Score: 40 3 | 4 | 5 | #include 6 | using namespace std; 7 | 8 | 9 | struct default_long_long_int{ 10 | int value = 0; 11 | }; 12 | 13 | 14 | struct custom_struct{ 15 | public: 16 | void insert(int num){ 17 | arr[num].value++; 18 | frequencies[arr[num].value].value++; 19 | frequencies[arr[num].value - 1].value--; 20 | } 21 | 22 | void remove(int num){ 23 | if (arr[num].value != 0){ 24 | arr[num].value--; 25 | frequencies[arr[num].value].value++; 26 | frequencies[arr[num].value + 1].value--; 27 | } 28 | 29 | if (arr[num].value == 0){ 30 | arr.erase(num); 31 | } 32 | }; 33 | 34 | int check(int value){ 35 | if (frequencies[value].value != 0) return 1; 36 | else return 0; 37 | } 38 | 39 | private: 40 | map arr; 41 | map frequencies; 42 | }; 43 | 44 | 45 | int main(){ 46 | int q; 47 | scanf("%d",&q); 48 | custom_struct arr; 49 | 50 | for (int i = 0; i < q; i++){ 51 | int command, value; 52 | scanf("%d",&command); 53 | scanf("%d",&value); 54 | 55 | if (command == 1){ 56 | arr.insert(value); 57 | } 58 | if (command == 2){ 59 | arr.remove(value); 60 | } 61 | if (command == 3){ 62 | printf("%d \n", arr.check(value)); 63 | } 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/03. Dictionaries and Hashmaps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(dictionaries-and-hashmaps) 4 | 5 | add_executable(task-1 001.\ Hash\ Tables\ -\ Ransom\ Note.cpp) 6 | add_executable(task-2 002.\ Two\ Strings.cpp) 7 | add_executable(task-3 003.\ Sherlock\ and\ Anagrams.cpp) 8 | add_executable(task-4 004.\ Count\ Triplets.cpp) 9 | add_executable(task-5 005.\ Frequency\ Queries.cpp) -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/04. Sorting/003. Sorting - Comparator.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/ctci-comparator-sorting 2 | // Score: 35 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | class player { 12 | public: 13 | player(string name, int score): name_(name), score_(score){} 14 | 15 | string get_name() const{ 16 | return name_; 17 | } 18 | 19 | int get_score() const{ 20 | return score_; 21 | } 22 | 23 | void print() const{ 24 | cout << name_ << " " << score_ << '\n'; 25 | } 26 | 27 | private: 28 | string name_; 29 | int score_; 30 | }; 31 | 32 | 33 | bool compare_players(player const & p1, player const & p2){ 34 | if (p1.get_score() > p2.get_score()) return true; 35 | else if (p1.get_score() == p2.get_score()) return p1.get_name() < p2.get_name(); 36 | else return false; 37 | } 38 | 39 | 40 | int main(){ 41 | int n; 42 | cin >> n; 43 | 44 | vector arr; 45 | 46 | for (int i = 0; i < n; i++){ 47 | string name; 48 | int score; 49 | cin >> name >> score; 50 | player tmp(name, score); 51 | arr.push_back(tmp); 52 | } 53 | 54 | sort(arr.begin(), arr.end(), compare_players); 55 | 56 | for (player const & el: arr){ 57 | el.print(); 58 | } 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/04. Sorting/004. Fraudulent Activity Notifications.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem 2 | // Score: 40 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | class moving_median{ 11 | public: 12 | 13 | explicit moving_median(int target_size): target_size(target_size){} 14 | 15 | void add(int value){ 16 | if (current_size < target_size){ 17 | current_size++; 18 | } 19 | else { 20 | check_operation(value); 21 | arr[q.front()]--; 22 | q.pop(); 23 | } 24 | 25 | arr[value]++; 26 | q.push(value); 27 | } 28 | 29 | int get_n_notifications(){ 30 | return n_notifications; 31 | } 32 | 33 | 34 | private: 35 | void check_operation(int value){ 36 | if (value >= two_medians()) n_notifications++; 37 | }; 38 | 39 | 40 | int find_i_element(int num){ 41 | int count = 0; 42 | for (int i = 0; i < 201; i++){ 43 | count += arr[i]; 44 | if (count >= num) return i; 45 | } 46 | return 200; 47 | }; 48 | 49 | 50 | int two_medians(){ 51 | return (find_i_element(target_size / 2 + 1) + find_i_element(target_size / 2 + target_size % 2)); 52 | }; 53 | 54 | 55 | int n_notifications = 0; 56 | int target_size; 57 | int current_size = 0; 58 | int arr[201] = {0}; 59 | queue q; 60 | }; 61 | 62 | 63 | int main(){ 64 | int n, d; 65 | cin >> n >> d; 66 | 67 | moving_median data(d); 68 | 69 | for (int i = 0; i < n; i++){ 70 | int tmp; 71 | cin >> tmp; 72 | data.add(tmp); 73 | } 74 | 75 | cout << data.get_n_notifications(); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/04. Sorting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(sorting) 4 | 5 | add_executable(task-3 003.\ Sorting\ -\ Comparator.cpp) 6 | add_executable(task-4 004.\ Fraudulent\ Activity\ Notifications.cpp) -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/001. Strings - Making Anagrams.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/ctci-making-anagrams/problem 2 | // Score: 25 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | string s1, s2; 13 | cin >> s1 >> s2; 14 | 15 | sort(s1.begin(), s1.end()); 16 | sort(s2.begin(), s2.end()); 17 | 18 | int i = 0; 19 | int j = 0; 20 | int ans = 0; 21 | while (i < s1.size() || j < s2.size()){ 22 | if (i >= s1.size()){ 23 | j++; 24 | ans++; 25 | } 26 | else if (j >= s2.size()){ 27 | i++; 28 | ans++; 29 | } 30 | else if (s1[i] == s2[j]){ 31 | i++; 32 | j++; 33 | } 34 | else if (s1[i] < s2[j]){ 35 | ans++; 36 | i++; 37 | } 38 | else if (s2[j] < s1[i]){ 39 | ans++; 40 | j++; 41 | } 42 | } 43 | 44 | cout << ans; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/002. Alternating Characters.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/alternating-characters/problem 2 | // Score: 20 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int t; 12 | cin >> t; 13 | 14 | for (int i = 0; i < t; i++) { 15 | string str; 16 | cin >> str; 17 | 18 | 19 | char prev = '0'; 20 | int ans = 0; 21 | 22 | for (char c: str){ 23 | if (c == prev) { 24 | ans++; 25 | } 26 | prev = c; 27 | } 28 | 29 | cout << ans << '\n'; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/003. Sherlock and the Valid String.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem 2 | // Score: 35 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | struct default_zero_int{ 12 | int val = 0; 13 | }; 14 | 15 | 16 | int main(){ 17 | string str; 18 | cin >> str; 19 | 20 | map arr; 21 | 22 | for (char c: str){ 23 | arr[c].val++; 24 | } 25 | 26 | map counts; 27 | 28 | for (auto el: arr){ 29 | counts[el.second.val].val++; 30 | } 31 | 32 | if (counts.size() <= 1){ 33 | cout << "YES"; 34 | } 35 | else if (counts.size() > 2){ 36 | cout << "NO"; 37 | } 38 | else { 39 | auto el1 = *counts.begin(); 40 | auto el2 = *(next(counts.begin(), 1)); 41 | 42 | if (((el1.first == 1 && el1.second.val == 1) || (el2.first == 1 && el2.second.val == 1)) || 43 | ((el1.second.val == 1 || el2.second.val == 1) && (abs(el1.first - el2.first) == 1))){ 44 | cout << "YES"; 45 | } 46 | else cout << "NO"; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/004. Special String Again.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/special-palindrome-again/problem 2 | // Score: 40 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int n; 13 | cin >> n; 14 | string str; 15 | cin >> str; 16 | 17 | vector> arr; 18 | arr.push_back(make_pair(str[0], 0)); 19 | 20 | for (char c: str){ 21 | if (c == arr.back().first){ 22 | arr.back().second++; 23 | } 24 | else { 25 | arr.push_back(make_pair(c, 1)); 26 | } 27 | } 28 | 29 | int ans = 0; 30 | for (int i = 0; i < arr.size(); i++){ 31 | ans += (arr[i].second + 1) * arr[i].second / 2; 32 | if ((i != 0) && (i != arr.size() - 1) && (arr[i].second == 1) && (arr[i - 1].first == arr[i + 1].first)){ 33 | ans += min(arr[i - 1].second, arr[i + 1].second); 34 | } 35 | } 36 | 37 | cout << ans; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/005. Common Child.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/common-child/problem 2 | // Score: 60 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | string s1, s2; 13 | cin >> s1 >> s2; 14 | 15 | vector> dp(s1.size() + 1, vector(s2.size() + 1, 0)); 16 | 17 | for (int i = 1; i < s1.size() + 1; i++){ 18 | for (int j = 1; j < s2.size() + 1; j++){ 19 | if (s1[i - 1] == s2[j - 1]){ 20 | dp[i][j] = dp[i - 1][j - 1] + 1; 21 | } 22 | else { 23 | dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]); 24 | } 25 | } 26 | } 27 | 28 | cout << dp[s1.size()][s2.size()]; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/05. String Manipulation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(string-manipulation) 4 | 5 | add_executable(task-1 001.\ Strings\ -\ Making\ Anagrams.cpp) 6 | add_executable(task-2 002.\ Alternating\ Characters.cpp) 7 | add_executable(task-3 003.\ Sherlock\ and\ the\ Valid\ String) 8 | add_executable(task-4 004.\ Special\ String\ Again.cpp) 9 | add_executable(task-5 005.\ Common\ Child.cpp) 10 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/06. Greedy Algorithms/001. Minimum Absolute Difference in an Array.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem 2 | // Score: 15 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int n; 13 | cin >> n; 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 | sort(arr.begin(), arr.end()); 23 | 24 | int ans = abs(arr[0] - arr[1]); 25 | for (int i = 1; i < arr.size(); i++){ 26 | if (abs(arr[i] - arr[i-1]) < ans){ 27 | ans = abs(arr[i] - arr[i-1]); 28 | } 29 | } 30 | 31 | cout << ans; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/06. Greedy Algorithms/002. Luck Balance.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/luck-balance/problem 2 | // Score: 20 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | 13 | int n, k; 14 | cin >> n >> k; 15 | 16 | int ans = 0; 17 | vector arr; 18 | 19 | for (int i = 0; i < n; i++){ 20 | int l, t; 21 | cin >> l >> t; 22 | 23 | if (t == 0) ans += l; 24 | else arr.push_back(l); 25 | } 26 | 27 | sort(arr.rbegin(), arr.rend()); 28 | 29 | for (int i = 0; i < arr.size(); i++){ 30 | if (i < k) ans += arr[i]; 31 | else ans -= arr[i]; 32 | } 33 | 34 | cout << ans; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/06. Greedy Algorithms/003. Greedy Florist.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/greedy-florist/problem 2 | // Score: 35 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int n, k; 13 | cin >> n >> k; 14 | vector arr; 15 | 16 | for (int i = 0; i < n; i++){ 17 | int tmp; 18 | cin >> tmp; 19 | arr.push_back(tmp); 20 | } 21 | 22 | sort(arr.rbegin(), arr.rend()); 23 | 24 | int ans = 0; 25 | int mult = 0; 26 | for (int i = 0; i < n; i++){ 27 | if (i % k == 0) mult++; 28 | ans += arr[i] * mult; 29 | } 30 | 31 | cout << ans; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/06. Greedy Algorithms/004. Max Min.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/angry-children/problem 2 | // Score: 35 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int n, k; 13 | cin >> n >> k; 14 | vector arr; 15 | 16 | for (int i = 0; i < n; i++){ 17 | int tmp; 18 | cin >> tmp; 19 | arr.push_back(tmp); 20 | } 21 | 22 | sort(arr.begin(), arr.end()); 23 | 24 | int ans = arr[k - 1] - arr[0]; 25 | for (int i = 0; i < arr.size() - k + 1; i++){ 26 | int tmp = arr[k - 1 + i] - arr[i]; 27 | if (tmp < ans) ans = tmp; 28 | } 29 | 30 | cout << ans; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/06. Greedy Algorithms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(greedy-algorithms) 4 | 5 | add_executable(task-1 001.\ Minimum\ Absolute\ Difference\ in\ an\ Array.cpp) 6 | add_executable(task-2 002.\ Luck\ Balance.cpp) 7 | add_executable(task-3 003.\ Greedy\ Florist.cpp) 8 | add_executable(task-4 004.\ Max\ Min.cpp) 9 | 10 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/07. Search/001. Hash Tables Ice Cream Parlor.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/ctci-ice-cream-parlor/problem 2 | // Score: 35 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int t = 0; 12 | cin >> t; 13 | 14 | for (int i = 0; i < t; i++){ 15 | int money, n; 16 | cin >> money >> n; 17 | map arr; 18 | 19 | for (int j = 0; j < n; j++){ 20 | int c; 21 | cin >> c; 22 | 23 | if (arr.find(c) == arr.end()){ 24 | arr[money - c] = j + 1; 25 | } 26 | else{ 27 | cout << arr[c] << " " << j + 1 << '\n'; 28 | } 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/07. Search/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(greedy-algorithms) 4 | 5 | add_executable(task-1 001.\ Hash\ Tables\ Ice\ Cream\ Parlor.cpp) 6 | 7 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/08. Dynamic Programming/001. Max Array Sum.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/max-array-sum/problem 2 | // Score: 20 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int n; 12 | cin >> n; 13 | vector arr(n); 14 | 15 | for (int i = 0; i < n; i++){ 16 | cin >> arr[i]; 17 | } 18 | 19 | vector dp(n); 20 | dp[0] = arr[0]; 21 | dp[1] = max(arr[0], arr[1]); 22 | for (int i = 2; i < n; i++){ 23 | dp[i] = max(max(dp[i-2] + arr[i], dp[i - 1]), arr[i]); 24 | } 25 | 26 | cout << dp[n - 1]; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/08. Dynamic Programming/002. Abbreviation.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/abbr/problem 2 | // Score: 40 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main(){ 12 | int q; 13 | cin >> q; 14 | 15 | for (int k = 0; k < q; k++){ 16 | string s1, s2; 17 | cin >> s1 >> s2; 18 | 19 | vector> dp (s2.size() + 1, vector (s1.size() + 1, false)); 20 | 21 | dp[0][0] = true; 22 | 23 | for (int i = 1; i < s2.size() + 1; i++){ 24 | dp[i][0] = false; 25 | } 26 | 27 | for (int i = 1; i < s1.size() + 1; i++){ 28 | dp[0][i] = (islower(s1[i - 1])) && (dp[0][i - 1] == true); 29 | } 30 | 31 | for (int i = 1; i < s2.size() + 1; i++){ 32 | for (int j = 1; j < s1.size() + 1; j++){ 33 | if (islower(s1[j-1])){ 34 | dp[i][j] = (dp[i - 1][j - 1] && s2[i - 1] == toupper(s1[j - 1])) || dp[i][j - 1]; 35 | } 36 | else { 37 | dp[i][j] = dp[i - 1][j - 1] && s2[i - 1] == s1[j - 1]; 38 | } 39 | 40 | } 41 | } 42 | 43 | if (dp[s2.size()][s1.size()]) cout << "YES" << endl; 44 | else cout << "NO" << endl; 45 | } 46 | return 0; 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/08. Dynamic Programming/003. Candies.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/candies/problem 2 | // Score: 50 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int n; 12 | cin >> n; 13 | vector arr(n); 14 | vector up (n, 1); 15 | vector down (n, 1); 16 | 17 | for (int i = 0; i < n; i++){ 18 | cin >> arr[i]; 19 | } 20 | 21 | for (int i = 1; i < n; i++){ 22 | if (arr[i] > arr[i - 1]){ 23 | up[i] = up[i - 1] + 1; 24 | } 25 | 26 | if (arr[n - i - 1] > arr[n - i]){ 27 | down[n - i - 1] = down[n - i] + 1; 28 | } 29 | } 30 | 31 | long long int ans = 0; 32 | for (int i = 0; i < n; i++){ 33 | ans += max(up[i], down[i]); 34 | } 35 | 36 | cout << ans; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/08. Dynamic Programming/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(dynamic-programming) 4 | 5 | add_executable(task-1 001.\ Max\ Array\ Sum.cpp) 6 | add_executable(task-2 "002. Abbreviation.cpp") 7 | add_executable(task-3 003.\ Candies.cpp) 8 | 9 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/09. Stacks and Queues/001. Balanced Brackets.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/balanced-brackets/problem 2 | // Score: 25 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | int t; 12 | cin >> t; 13 | 14 | for (int i = 0; i < t; i++){ 15 | string str; 16 | cin >> str; 17 | vector brackets; 18 | 19 | bool ans = true; 20 | 21 | for (char c: str){ 22 | if (c == ')' || c == ']' || c == '}'){ 23 | if ((!brackets.empty()) && ( 24 | (c == ')' && brackets.back() == '(') || 25 | (c == ']' && brackets.back() == '[') || 26 | (c == '}' && brackets.back() == '{'))){ 27 | brackets.pop_back(); 28 | } 29 | else { 30 | ans = false; 31 | break; 32 | } 33 | } 34 | else brackets.push_back(c); 35 | } 36 | 37 | if (ans && brackets.empty()) cout << "YES" << endl; 38 | else cout << "NO" << endl; 39 | } 40 | 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/09. Stacks and Queues/003. Largest Rectangle.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/largest-rectangle/problem 2 | // Score: 50 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | void update_ans(long long int & ans, int i, vector & positions, vector & heights){ 11 | long long int square; 12 | square = heights.back() * (i - positions.back()); 13 | ans = max(ans, square); 14 | heights.pop_back(); 15 | positions.pop_back(); 16 | } 17 | 18 | 19 | int main (){ 20 | int n; 21 | cin >> n; 22 | 23 | vector arr(n); 24 | for (int i = 0; i < n; i++){ 25 | cin >> arr[i]; 26 | } 27 | 28 | vector positions; 29 | vector heights; 30 | 31 | long long int ans = 0; 32 | 33 | for (int i = 0; i < n; i++){ 34 | if (heights.empty() || arr[i] > heights.back()){ 35 | heights.push_back(arr[i]); 36 | positions.push_back(i); 37 | } 38 | 39 | else if (arr[i] < heights.back()){ 40 | int last_position = positions.back(); 41 | 42 | while (!heights.empty() && heights.back() > arr[i]){ 43 | last_position = positions.back(); 44 | update_ans(ans, i, positions, heights); 45 | } 46 | positions.push_back(last_position); 47 | heights.push_back(arr[i]); 48 | } 49 | } 50 | 51 | while (!heights.empty()){ 52 | update_ans(ans, n, positions, heights); 53 | } 54 | 55 | cout << ans; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/09. Stacks and Queues/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(stacks-and-queues) 4 | 5 | 6 | add_executable(task-1 "001. Balanced Brackets.cpp") 7 | add_executable(task-3 "003. Largest Rectangle.cpp") 8 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/10. Graphs/003. BFS - Shortest Reach in a Graph.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/ctci-bfs-shortest-reach/problem 2 | // Score: 45 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | struct node{ 12 | bool visited = false; 13 | int path = -1; 14 | vector kids; 15 | }; 16 | 17 | 18 | int main(){ 19 | int t; 20 | cin >> t; 21 | for (int k = 0; k < t; k++){ 22 | int n, m; 23 | cin >> n >> m; 24 | 25 | vector nodes(n); 26 | for (int i = 0; i < n; i++){ 27 | nodes[i] = new node(); 28 | } 29 | 30 | for (int i = 0; i < m; i++){ 31 | int a, b; 32 | cin >> a >> b; 33 | nodes[a-1]->kids.push_back(nodes[b-1]); 34 | nodes[b-1]->kids.push_back(nodes[a-1]); 35 | } 36 | 37 | int start; 38 | cin >> start; 39 | 40 | deque q; 41 | q.push_back(nodes[start - 1]); 42 | 43 | int path = 0; 44 | q.front()->path = 0; 45 | q.front()->visited = true; 46 | 47 | while (!q.empty()){ 48 | path = q.front()->path + 6; 49 | 50 | for (node * el: q.front()->kids){ 51 | if (!el->visited){ 52 | el->path = path; 53 | el->visited = true; 54 | q.push_back(el); 55 | } 56 | } 57 | q.pop_front(); 58 | } 59 | 60 | for (node* el: nodes){ 61 | if (el->path != 0) cout << el->path << " "; 62 | } 63 | cout << '\n'; 64 | } 65 | return 0; 66 | } -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/10. Graphs/004. DFS - Connected Cell in a Grid.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/ctci-connected-cell-in-a-grid/problem 2 | // Score: 45 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | void count_nodes(vector> const & arr, vector> & visited, int i, int j, int & count){ 11 | if (visited[i][j]) return; 12 | 13 | visited[i][j] = true; 14 | if (arr[i][j] == 0) return; 15 | if (i != 0) count_nodes(arr, visited, i - 1, j, count); 16 | if (i != 0 && j != 0) count_nodes(arr, visited, i - 1, j - 1, count); 17 | if (i != 0 && j != arr[0].size() - 1) count_nodes(arr, visited, i - 1, j + 1, count); 18 | if (j != 0) count_nodes(arr, visited, i, j - 1, count); 19 | if (j != arr[0].size() - 1) count_nodes(arr, visited, i, j + 1, count); 20 | if (i != arr.size() - 1) count_nodes(arr, visited, i + 1, j, count); 21 | if (i != arr.size() - 1 && j != 0) count_nodes(arr, visited, i + 1, j - 1, count); 22 | if (i != arr.size() - 1 && j != arr[0].size() - 1) count_nodes(arr, visited, i + 1, j + 1, count); 23 | count++; 24 | } 25 | 26 | 27 | int main(){ 28 | int n, m; 29 | cin >> n >> m; 30 | 31 | vector> arr(n, vector(m)); 32 | 33 | for (int i = 0; i < n; i++){ 34 | for (int j = 0; j < m; j++){ 35 | cin >> arr[i][j]; 36 | } 37 | } 38 | 39 | vector> visited(n, vector(m, false)); 40 | 41 | 42 | int ans = 0; 43 | 44 | for (int i = 0; i < n; i++){ 45 | for (int j = 0; j < m; j++){ 46 | int count = 0; 47 | count_nodes(arr, visited, i, j, count); 48 | if (count > ans){ 49 | ans = count; 50 | } 51 | } 52 | } 53 | 54 | cout << ans; 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/10. Graphs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(graphs) 4 | 5 | 6 | add_executable(task-3 "003. BFS - Shortest Reach in a Graph.cpp") 7 | add_executable(task-4 "004. DFS - Connected Cell in a Grid.cpp") 8 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/11. Trees/001. Tree - Height of a Binary Tree.cpp: -------------------------------------------------------------------------------- 1 | // Problem: https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree/problem 2 | // Score: 10 3 | 4 | 5 | int height(Node *root) { 6 | if ((root == nullptr) || (root->left == nullptr && root->right == nullptr)) { 7 | return 0; 8 | } else { 9 | return max(height(root->left), height(root->right)) + 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Interview Preparation Kit - CPP/11. Trees/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | project(trees) 4 | 5 | 6 | add_executable(task-1 "001. Tree - Height of a Binary Tree.cpp") 7 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/01. Warm-up Challenges/001. Sock Merchant.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/sock-merchant/problem 2 | # Score: 10 3 | 4 | 5 | def sock_merchant(ar): 6 | list_of_socks = [0 for i in range(101)] 7 | for element in ar: 8 | list_of_socks[element] = list_of_socks[element] + 1 9 | ans = 0 10 | for sock in list_of_socks: 11 | ans += sock // 2 12 | return ans 13 | 14 | 15 | n = int(input().strip()) 16 | ar = list(map(int, input().strip().split(' '))) 17 | result = sock_merchant(ar) 18 | print(result) 19 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/01. Warm-up Challenges/002. Counting Valleys.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/counting-valleys/problem 2 | # Score: 15 3 | 4 | 5 | def counting_valleys(n, s): 6 | current_level = 0 7 | count = 0 8 | for i in range(n): 9 | if s[i] == 'U': 10 | current_level += 1 11 | elif s[i] == 'D': 12 | current_level -= 1 13 | if current_level == -1: 14 | count += 1 15 | return count 16 | 17 | 18 | n = int(input().strip()) 19 | s = input().strip() 20 | result = counting_valleys(n, s) 21 | print(result) 22 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/01. Warm-up Challenges/003. Jumping on the Clouds.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem 2 | # Score: 20 3 | 4 | 5 | def jumping_on_clouds(n, c): 6 | c.append(0) 7 | ans = 0 8 | position = 0 9 | while position < n-1: 10 | position += (c[position+2] == 0) + 1 11 | ans += 1 12 | return ans 13 | 14 | 15 | n = int(input()) 16 | c = list(map(int, input().rstrip().split())) 17 | print(jumping_on_clouds(n, c)) 18 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/01. Warm-up Challenges/004. Repeated String.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/repeated-string/problem 2 | # Score: 20 3 | 4 | 5 | def repeated_string(s, n): 6 | return n // len(s) * s.count('a') + s[0: n % len(s)].count('a') 7 | 8 | 9 | s = input() 10 | n = int(input()) 11 | print(repeated_string(s, n)) 12 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/02. Arrays/001. Arrays - Left Rotation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem 2 | # Score: 20 3 | 4 | 5 | def array_left_rotation(a, k): 6 | result = a[k:] + a[:k] 7 | return result 8 | 9 | 10 | n, k = map(int, input().strip().split(' ')) 11 | a = list(map(int, input().strip().split(' '))) 12 | print(*array_left_rotation(a, k)) 13 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/02. Arrays/002. 2D Array - DS.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/2d-array/problem 2 | # Score: 15 3 | 4 | 5 | def hourglasses(arr, i, j): 6 | return sum(arr[i][j:j+3]) + arr[i+1][j+1] + sum(arr[i+2][j:j+3]) 7 | 8 | 9 | arr = [] 10 | for i in range(6): 11 | arr.append(list(map(int, input().split()))) 12 | 13 | ans = hourglasses(arr, 0, 0) 14 | for i in range(4): 15 | for j in range(4): 16 | ans = max(ans, hourglasses(arr, i, j)) 17 | print(ans) 18 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/02. Arrays/003. New Year Chaos.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/new-year-chaos/problem 2 | # Score: 40 3 | 4 | 5 | t = int(input()) 6 | for test in range(t): 7 | n = int(input()) 8 | arr = list(map(int, input().split())) 9 | count = 0 10 | 11 | for i in range(2): 12 | for j in range(len(arr) - 1, 0, -1): 13 | if arr[j] < arr[j-1]: 14 | arr[j], arr[j-1] = arr[j-1], arr[j] 15 | count += 1 16 | 17 | if arr == sorted(arr): 18 | print(count) 19 | else: 20 | print('Too chaotic') 21 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/02. Arrays/004. Minimum Swaps 2.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/minimum-swaps-2/problem 2 | # Score: 40 3 | 4 | 5 | n = int(input()) 6 | arr = list(map(int, input().split())) 7 | count = 0 8 | 9 | i = 0 10 | while i < len(arr): 11 | if arr[i] != i + 1: 12 | arr[arr[i] - 1], arr[i] = arr[i], arr[arr[i] - 1] 13 | count += 1 14 | else: 15 | i += 1 16 | 17 | print(count) 18 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/02. Arrays/005. Array Manipulation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/crush/problem 2 | # Score: 60 3 | 4 | 5 | n, queries = map(int, input().split()) 6 | 7 | arr = [0 for i in range(n+2)] 8 | 9 | for i in range(queries): 10 | start, finish, k = map(int, input().split()) 11 | arr[start - 1] += k 12 | arr[finish] -= k 13 | 14 | ans = 0 15 | current = 0 16 | for i in arr: 17 | current += i 18 | if current > ans: 19 | ans = current 20 | 21 | print(ans) 22 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/03. Dictionaries and Hashmaps/001. Hash Tables - Ransom Note.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/ctci-ransom-note/problem 2 | # Score: 25 3 | 4 | 5 | from collections import Counter 6 | 7 | 8 | def checkMagazine(magazine, note): 9 | if Counter(note) - Counter(magazine) == {}: 10 | return 'Yes' 11 | else: 12 | return 'No' 13 | 14 | 15 | m, n = map(int, input().split()) 16 | magazine = list(input().split()) 17 | note = list(input().split()) 18 | print(checkMagazine(magazine, note)) 19 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/03. Dictionaries and Hashmaps/002. Two Strings.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/two-strings/problem 2 | # Score: 25 3 | 4 | 5 | for i in range(int(input())): 6 | str1 = set(input()) 7 | str2 = set(input()) 8 | if str1 & str2 != set(): 9 | print('YES') 10 | else: 11 | print('NO') 12 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/03. Dictionaries and Hashmaps/003. Count Triplets.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/count-triplets-1/problem 2 | # Score: 25 3 | 4 | 5 | from collections import defaultdict 6 | 7 | 8 | def count_triplets(arr, r): 9 | arr2 = defaultdict(int) 10 | arr3 = defaultdict(int) 11 | count = 0 12 | for i in arr: 13 | count += arr3[i] 14 | arr3[i*r] += arr2[i] 15 | arr2[i*r] += 1 16 | return count 17 | 18 | 19 | n, r = map(int, input().split()) 20 | arr = list(map(int, input().split())) 21 | print(count_triplets(arr, r)) 22 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/03. Dictionaries and Hashmaps/004. Frequency Queries.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/frequency-queries/problem 2 | # Score: 40 3 | 4 | 5 | from collections import defaultdict 6 | 7 | 8 | arr = defaultdict(int) 9 | frequencies = defaultdict(int) 10 | result = [] 11 | for i in range(int(input())): 12 | command, value = map(int, input().split()) 13 | if command == 1: 14 | arr[value] += 1 15 | frequencies[arr[value]] += 1 16 | frequencies[arr[value] - 1] -= 1 17 | if command == 2 and arr[value] != 0: 18 | arr[value] -= 1 19 | frequencies[arr[value]] += 1 20 | frequencies[arr[value] + 1] -= 1 21 | if command == 3: 22 | result.append(1 if frequencies[value] > 0 else 0) 23 | 24 | for i in result: 25 | print(i) 26 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/03. Dictionaries and Hashmaps/005. Sherlock and Anagrams.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem 2 | # Score: 50 3 | 4 | 5 | from collections import defaultdict 6 | 7 | 8 | for t in range(int(input())): 9 | s = input() 10 | substrings = defaultdict(int) 11 | 12 | for i in range(1, len(s)): 13 | for j in range(len(s) - i + 1): 14 | substrings[''.join(sorted(s[j:j+i]))] += 1 15 | 16 | ans = 0 17 | for key, value in substrings.items(): 18 | ans += value*(value-1) // 2 19 | 20 | print(ans) 21 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/04. Sorting/001. Sorting - Bubble Sort.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/ctci-bubble-sort/problem 2 | # Score: 30 3 | 4 | 5 | n = int(input()) 6 | a = list(map(int, input().split())) 7 | 8 | count = 0 9 | 10 | for i in range(n): 11 | for j in range(n-1): 12 | if a[j] > a[j+1]: 13 | a[j], a[j+1] = a[j+1], a[j] 14 | count += 1 15 | 16 | print('Array is sorted in', count, 'swaps.') 17 | print('First Element:', a[0]) 18 | print('Last Element:', a[-1]) 19 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/04. Sorting/002. Mark and Toys.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/mark-and-toys/problem 2 | # Score: 35 3 | 4 | 5 | n, k = map(int, input().split()) 6 | prices = sorted(list(map(int, input().split()))) 7 | 8 | count = 0 9 | total_sum = 0 10 | for i in prices: 11 | total_sum += i 12 | if total_sum > k: 13 | break 14 | else: 15 | count += 1 16 | print(count) 17 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/07. Search/001. Hash Tables - Ice Cream Parlor.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/ctci-ice-cream-parlor/problem 2 | # Score: 35 3 | 4 | 5 | t = int(input()) 6 | for i in range(t): 7 | money = int(input()) 8 | n = int(input()) 9 | arr = list(map(int, input().split())) 10 | 11 | saved_values = {} 12 | for counter, value in enumerate(arr): 13 | if money-value in saved_values: 14 | print(saved_values[money-value] + 1, counter + 1) 15 | elif value not in saved_values: 16 | saved_values[value] = counter 17 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/07. Search/002. Minimum Time Required.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/minimum-time-required/problem 2 | # Score: 35 3 | 4 | 5 | import math 6 | 7 | 8 | def minimum_time(goal, machines): 9 | min_days = math.ceil(goal / (len(machines) / min(machines))) 10 | max_days = math.ceil(goal / (len(machines) / max(machines))) 11 | while min_days < max_days: 12 | day = (min_days + max_days) // 2 13 | if sum(day // i for i in machines) >= goal: 14 | max_days = day 15 | else: 16 | min_days = day + 1 17 | return min_days 18 | 19 | 20 | n, goal = map(int, input().split()) 21 | machines = list(map(int, input().split())) 22 | print(minimum_time(goal, machines)) 23 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/07. Search/003. Triple sum.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/triple-sum/problem 2 | # Score: 40 3 | 4 | 5 | def binary_search_last(arr, el, low, high): 6 | if low + 1 >= high: 7 | if arr[low] > el: 8 | return 0 9 | else: 10 | return low + 1 11 | middle = (low + high) // 2 12 | if arr[middle] > el: 13 | return binary_search_last(arr, el, low, middle) 14 | else: 15 | return binary_search_last(arr, el, middle, high) 16 | 17 | 18 | len_a, len_b, len_c = map(int, input().split()) 19 | a = sorted(set(map(int, input().split()))) 20 | b = sorted(list(set(map(int, input().split())))) 21 | c = sorted(list(set(map(int, input().split())))) 22 | 23 | ans = 0 24 | for i in set(b): 25 | ans += binary_search_last(a, i, 0, len(a)) * binary_search_last(c, i, 0, len(c)) 26 | print(ans) 27 | -------------------------------------------------------------------------------- /Interview Preparation Kit - Python/08. Dynamic Programming/001. Max Array Sum.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/max-array-sum/problem 2 | # Score: 20 3 | 4 | 5 | def max_subset_sum(arr): 6 | dp = list() 7 | dp.append(arr[0]) 8 | dp.append(max(arr[:2])) 9 | ans = dp[-1] 10 | for i in arr[2:]: 11 | dp.append(max(i, dp[-2] + i, ans)) 12 | ans = max(ans, dp[-1]) 13 | return ans 14 | 15 | 16 | n = int(input()) 17 | arr = list(map(int, input().split())) 18 | print(max_subset_sum(arr)) 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alexander Marinskiy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Python/01. Introduction/001. Say Hello, World! With Python.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-hello-world/problem 2 | # Score: 5 3 | 4 | 5 | print('Hello, World!') 6 | -------------------------------------------------------------------------------- /Python/01. Introduction/002. Python If-Else.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-if-else/problem 2 | # Score: 10 3 | 4 | 5 | def wierd(n): 6 | if n % 2 == 1 or 6 <= n <= 20: 7 | print('Weird') 8 | else: 9 | print('Not Weird') 10 | 11 | 12 | wierd(int(input())) 13 | -------------------------------------------------------------------------------- /Python/01. Introduction/003. Arithmetic Operators.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-arithmetic-operators/submissions/code/70402456 2 | # Score: 10 3 | 4 | 5 | a, b = int(input()), int(input()) 6 | print((a + b), (a - b), (a * b), sep='\n') 7 | -------------------------------------------------------------------------------- /Python/01. Introduction/004. Python Division.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-division/problem 2 | # Score: 10 3 | 4 | 5 | a, b = int(input()), int(input()) 6 | print(a // b, a / b, sep='\n') 7 | -------------------------------------------------------------------------------- /Python/01. Introduction/005. Loops.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-loops/problem 2 | # Score: 10 3 | 4 | 5 | for i in range(int(input())): 6 | print(i ** 2) 7 | -------------------------------------------------------------------------------- /Python/01. Introduction/006. Write a function.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/write-a-function/problem 2 | # Score: 10 3 | 4 | 5 | def is_leap(y): 6 | return y % 4 == 0 and (y % 100 != 0 or y % 400 == 0) 7 | -------------------------------------------------------------------------------- /Python/01. Introduction/007. Print Function.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-print/problem 2 | # Score: 20 3 | 4 | 5 | for i in range(1, int(input()) + 1): 6 | print(i, end='') 7 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/001. List Comprehensions.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/list-comprehensions/problem 2 | # Score: 10 3 | 4 | 5 | x, y, z, n = [int(input()) for _ in range(4)] 6 | listOfAnswers = [[i, j, k] for i in range(x + 1) for j in range(y + 1) for k in range(z + 1) if i + j + k != n] 7 | print(listOfAnswers) 8 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/002. Find the Runner-Up Score!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem 2 | # Score: 10 3 | 4 | 5 | n = int(input()) 6 | arr = list(map(int, input().split())) 7 | print(max([x for x in arr if x != max(arr)])) 8 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/003. Nested Lists.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/nested-list/problem 2 | # Score: 10 3 | 4 | 5 | def secondLowestGrade(classList): 6 | secondLowestScore = sorted(set(_[1] for _ in classList))[1] 7 | result = sorted([_[0] for _ in classList if _[1] == secondLowestScore]) 8 | return result 9 | 10 | 11 | numberOfStudents = int(input()) 12 | classList = [] 13 | for i in range(numberOfStudents): 14 | classList.append([str(input()), float(input())]) 15 | print('\n'.join(secondLowestGrade(classList))) 16 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/004. Finding the percentage.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/finding-the-percentage/problem 2 | # Score: 10 3 | 4 | 5 | def readScores(listOfStudents): 6 | line = list(input().split()) 7 | avScore = sum(map(float, line[1:])) / 3 8 | name = line[0] 9 | listOfStudents[name] = avScore 10 | 11 | 12 | n = int(input()) 13 | listOfStudents = dict() 14 | for i in range(n): 15 | readScores(listOfStudents) 16 | print('%.2f' % listOfStudents[input()]) 17 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/005. Lists.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-lists/problem 2 | # Score: 10 3 | 4 | 5 | def handler(result): 6 | inp = input().split() 7 | command = inp[0] 8 | values = inp[1:] 9 | if command == 'print': 10 | print(result) 11 | else: 12 | execute = 'result.' + command + "(" + ",".join(values) + ")" 13 | eval(execute) 14 | 15 | 16 | result = [] 17 | for i in range(int(input())): 18 | handler(result) 19 | -------------------------------------------------------------------------------- /Python/02. Basic Data Types/006. Tuples.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-tuples/problem 2 | # Score: 10 3 | 4 | 5 | n = int(input()) 6 | print(hash(tuple(map(int, input().split())))) 7 | -------------------------------------------------------------------------------- /Python/03. Strings/001. sWAP cASE.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/swap-case/problem 2 | # Score: 10 3 | 4 | 5 | def swap_case(s): 6 | return s.swapcase() 7 | -------------------------------------------------------------------------------- /Python/03. Strings/002. String Split and Join.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-string-split-and-join/problem 2 | # Score: 10 3 | 4 | 5 | def split_and_join(line): 6 | return "-".join(line.split()) 7 | -------------------------------------------------------------------------------- /Python/03. Strings/003. What's Your Name.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/whats-your-name/problem 2 | # Score: 10 3 | 4 | 5 | def print_full_name(first_name, last_name): 6 | print("Hello {} {}! You just delved into python.".format(first_name, last_name)) 7 | -------------------------------------------------------------------------------- /Python/03. Strings/004. Mutations.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-mutations/problem 2 | # Score: 10 3 | 4 | 5 | def mutate_string(string, position, character): 6 | return string[:position] + character + string[position + 1:] 7 | -------------------------------------------------------------------------------- /Python/03. Strings/005. Find a string.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/find-a-string/problem 2 | # Score: 10 3 | 4 | 5 | def count_substring(string, sub_string): 6 | count = 0 7 | for i in range(len(string) - len(sub_string) + 1): 8 | if string[i: i + len(sub_string)] == sub_string: 9 | count += 1 10 | return count 11 | -------------------------------------------------------------------------------- /Python/03. Strings/006. String Validators.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/string-validators/problem 2 | # Score: 10 3 | 4 | 5 | s = input() 6 | print(any([char.isalnum() for char in s])) 7 | print(any([char.isalpha() for char in s])) 8 | print(any([char.isdigit() for char in s])) 9 | print(any([char.islower() for char in s])) 10 | print(any([char.isupper() for char in s])) 11 | -------------------------------------------------------------------------------- /Python/03. Strings/007. Text Alignment.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/text-alignment/problem 2 | # Score: 10 3 | 4 | 5 | # Replace all ______ with rjust, ljust or center. 6 | 7 | thickness = int(input()) # This must be an odd number 8 | c = 'H' 9 | 10 | # Top Cone 11 | for i in range(thickness): 12 | print((c*i).rjust(thickness-1)+c+(c*i).ljust(thickness-1)) 13 | 14 | # Top Pillars 15 | for i in range(thickness+1): 16 | print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) 17 | 18 | # Middle Belt 19 | for i in range((thickness+1)//2): 20 | print((c*thickness*5).center(thickness*6)) 21 | 22 | # Bottom Pillars 23 | for i in range(thickness+1): 24 | print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6)) 25 | 26 | # Bottom Cone 27 | for i in range(thickness): 28 | print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-1)).ljust(thickness)).rjust(thickness*6)) 29 | -------------------------------------------------------------------------------- /Python/03. Strings/008. Text Wrap.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/text-wrap/problem 2 | # Score: 10 3 | 4 | 5 | def wrap(string, max_width): 6 | return textwrap.fill(string, max_width) 7 | -------------------------------------------------------------------------------- /Python/03. Strings/009. Designer Door Mat.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/designer-door-mat/problem 2 | # Score: 10 3 | 4 | 5 | height, length = map(int, input().split()) 6 | for i in range(0, height // 2): 7 | s = '.|.' * (i * 2 + 1) 8 | print(s.center(length,'-')) 9 | print('WELCOME'.center(length, '-')) 10 | for i in range(height // 2 - 1, -1, -1): 11 | s = '.|.' * (i * 2 + 1) 12 | print(s.center(length,'-')) 13 | -------------------------------------------------------------------------------- /Python/03. Strings/010. String Formatting.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-string-formatting/problem 2 | # Score: 10 3 | 4 | 5 | def print_formatted(number): 6 | width = len("{0:b}".format(number)) 7 | for i in range(1, number + 1): 8 | print("{0:{width}d} {0:{width}o} {0:{width}X} {0:{width}b}".format(i, width=width)) 9 | -------------------------------------------------------------------------------- /Python/03. Strings/011. Capitalize!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/capitalize/problem 2 | # Score: 20 3 | 4 | 5 | st = input() 6 | print(' '.join(word.capitalize() for word in st.split(' '))) 7 | -------------------------------------------------------------------------------- /Python/04. Sets/001. Introduction to Sets.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-introduction-to-sets/problem 2 | # Score: 10 3 | 4 | 5 | def average(array): 6 | return sum(set(array)) / len(set(array)) 7 | -------------------------------------------------------------------------------- /Python/04. Sets/002. No Idea!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/no-idea/problem 2 | # Score: 50 3 | 4 | 5 | _ = input() 6 | array = input().split() 7 | like = set(input().split()) 8 | dislike = set(input().split()) 9 | print(sum((i in like) - (i in dislike) for i in array)) 10 | -------------------------------------------------------------------------------- /Python/04. Sets/003. Symmetric Difference.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/symmetric-difference/problem 2 | # Score: 10 3 | 4 | 5 | i, m = input(), set(map(int, input().split())) 6 | i, n = input(), set(map(int, input().split())) 7 | print(*sorted(m.symmetric_difference(n)), sep='\n') 8 | -------------------------------------------------------------------------------- /Python/04. Sets/004. Set add().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-add/problem 2 | # Score: 10 3 | 4 | 5 | print(len(set(input() for i in range(int(input()))))) 6 | -------------------------------------------------------------------------------- /Python/04. Sets/005. Set discard() remove() pop().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem 2 | # Score: 10 3 | 4 | 5 | n = int(input()) 6 | s = set(map(int, input().split())) 7 | for i in range(int(input())): 8 | string = input().split() 9 | if string[0] == 'pop': 10 | s.pop() 11 | elif string[0] == 'remove': 12 | s.remove(int(string[1])) 13 | elif string[0] == 'discard': 14 | s.discard(int(string[1])) 15 | print(sum(s)) 16 | -------------------------------------------------------------------------------- /Python/04. Sets/006. Set union() Operation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-union/problem 2 | # Score: 10 3 | 4 | 5 | _, a = input(), set(input().split()) 6 | _, b = input(), set(input().split()) 7 | print(len(a.union(b))) 8 | -------------------------------------------------------------------------------- /Python/04. Sets/007. Set intersection() Operation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-intersection-operation/problem 2 | # Score: 10 3 | 4 | 5 | _, a = input(), set(input().split()) 6 | _, b = input(), set(input().split()) 7 | print(len(a.intersection(b))) 8 | -------------------------------------------------------------------------------- /Python/04. Sets/008. Set difference() Operation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-difference-operation/problem 2 | # Score: 10 3 | 4 | 5 | _, a = input(), set(input().split()) 6 | _, b = input(), set(input().split()) 7 | print(len(a.difference(b))) 8 | -------------------------------------------------------------------------------- /Python/04. Sets/009. Set symmetric_difference() Operation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-symmetric-difference-operation/problem 2 | # Score: 10 3 | 4 | 5 | _, a = input(), set(input().split()) 6 | _, b = input(), set(input().split()) 7 | print(len(a.symmetric_difference(b))) 8 | -------------------------------------------------------------------------------- /Python/04. Sets/010. Set Mutations.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-set-mutations/problem 2 | # Score: 10 3 | 4 | 5 | def handler(a): 6 | command = input().split()[0] 7 | new_set = set(map(int, input().split())) 8 | if command == 'intersection_update': 9 | a.intersection_update(new_set) 10 | if command == 'update': 11 | a.update(new_set) 12 | if command == 'symmetric_difference_update': 13 | a.symmetric_difference_update(new_set) 14 | if command == 'difference_update': 15 | a.difference_update(new_set) 16 | 17 | 18 | _, a = input(), set(map(int, input().split())) 19 | for i in range(int(input())): 20 | handler(a) 21 | print(sum(a)) 22 | -------------------------------------------------------------------------------- /Python/04. Sets/011. The Captain's Room.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-the-captains-room/problem 2 | # Score: 10 3 | 4 | 5 | k = int(input()) 6 | room_number_list = list(map(int, input().split())) 7 | captain_room_number = (sum(set(room_number_list)) * k - sum(room_number_list)) // (k - 1) 8 | print(captain_room_number) 9 | -------------------------------------------------------------------------------- /Python/04. Sets/012. Check Subset.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-check-subset/problem 2 | # Score: 10 3 | 4 | 5 | for i in range(int(input())): 6 | _, a = input(), set(map(int, input().split())) 7 | _, b = input(), set(map(int, input().split())) 8 | print(a.issubset(b)) 9 | -------------------------------------------------------------------------------- /Python/04. Sets/013. Check Strict Superset.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-check-strict-superset/problem 2 | # Score: 10 3 | 4 | 5 | a = set(input().split()) 6 | print(all(a > set(input().split()) for _ in range(int(input())))) 7 | -------------------------------------------------------------------------------- /Python/06. Itertools/001. itertools.product().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/itertools-product/problem 2 | # Score: 10 3 | 4 | 5 | from itertools import product 6 | 7 | 8 | a = list(map(int, input().split())) 9 | b = list(map(int, input().split())) 10 | print(*list(product(a, b))) 11 | -------------------------------------------------------------------------------- /Python/06. Itertools/002. itertools.combinations().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/itertools-combinations/problem 2 | # Score: 10 3 | 4 | 5 | import itertools 6 | 7 | 8 | s = input().split() 9 | string, number = sorted(s[0]), int(s[1]) 10 | for i in range(1, number + 1): 11 | print(*list(map(''.join, itertools.combinations(string, i))), sep='\n') 12 | -------------------------------------------------------------------------------- /Python/06. Itertools/003. itertools.permutations().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/itertools-permutations/problem 2 | # Score: 10 3 | 4 | 5 | import itertools 6 | 7 | 8 | s = input().split() 9 | string, number = sorted(s[0]), int(s[1]) 10 | print(*list(map(''.join, itertools.permutations(string, number))), sep='\n') 11 | -------------------------------------------------------------------------------- /Python/06. Itertools/004. itertools.combinations_with_replacement().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/itertools-combinations-with-replacement/problem 2 | # Score: 10 3 | 4 | 5 | import itertools 6 | 7 | 8 | s = input().split() 9 | string, number = sorted(s[0]), int(s[1]) 10 | print(*list(map(''.join, itertools.combinations_with_replacement(string, number))), sep='\n') 11 | -------------------------------------------------------------------------------- /Python/06. Itertools/005. Compress the String!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/compress-the-string/problem 2 | # Score: 20 3 | 4 | 5 | from itertools import groupby 6 | 7 | 8 | print(*[(len(list(c)), int(x)) for x, c in groupby(input())]) 9 | -------------------------------------------------------------------------------- /Python/06. Itertools/006. Iterables and Iterators.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/iterables-and-iterators/problem 2 | # Score: 40 3 | 4 | 5 | n, number, k = int(input()), input().split().count('a'), int(input()) 6 | not_a = 1 7 | for i in range(k): 8 | not_a = not_a * (n - number - i) / (n - i) 9 | print(1-not_a) 10 | -------------------------------------------------------------------------------- /Python/06. Itertools/007. Maximize It!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/maximize-it/problem 2 | # Score: 50 3 | 4 | 5 | from itertools import product 6 | 7 | k, m = map(int, input().split()) 8 | n = (list(map(int, input().split()))[1:] for _ in range(k)) 9 | results = (sum(i**2 for i in x) % m for x in product(*n)) 10 | print(max(results)) 11 | -------------------------------------------------------------------------------- /Python/07. Collections/001. collections.Counter().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/collections-counter/problem 2 | # Score: 10 3 | 4 | 5 | import collections 6 | 7 | 8 | number_of_shoes = int(input()) 9 | sizes_in_stock = collections.Counter(map(int, input().split())) 10 | 11 | total_revenue = 0 12 | 13 | for _ in range(int(input())): 14 | size, price = map(int, input().split()) 15 | if sizes_in_stock[size]: 16 | total_revenue += price 17 | sizes_in_stock[size] -= 1 18 | 19 | print(total_revenue) 20 | -------------------------------------------------------------------------------- /Python/07. Collections/002. DefaultDict Tutorial.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/defaultdict-tutorial/problem 2 | # Score: 20 3 | 4 | 5 | from collections import defaultdict 6 | 7 | 8 | n, m = map(int, input().split()) 9 | d = defaultdict(list) 10 | for i in range(1, n + 1): 11 | d[input()].append(str(i)) 12 | for i in range(m): 13 | print(' '.join(d[input()]) or -1) 14 | -------------------------------------------------------------------------------- /Python/07. Collections/003. Collections namedtuple().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-collections-namedtuple/problem 2 | # Score: 20 3 | 4 | 5 | from collections import namedtuple 6 | 7 | 8 | n, Student = int(input()), namedtuple('Student', input()) 9 | print("{:.2f}".format(sum([int(Student(*input().split()).MARKS) for _ in range(n)]) / n)) 10 | -------------------------------------------------------------------------------- /Python/07. Collections/004. Collections OrderedDict().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-collections-ordereddict/problem 2 | # Score: 20 3 | 4 | 5 | from collections import OrderedDict 6 | 7 | 8 | ordered_dictionary = OrderedDict() 9 | for _ in range(int(input())): 10 | item, price = input().rsplit(' ', 1) 11 | ordered_dictionary[item] = ordered_dictionary.get(item, 0) + int(price) 12 | [print(item, ordered_dictionary[item]) for item in ordered_dictionary] 13 | -------------------------------------------------------------------------------- /Python/07. Collections/005. Word Order.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/word-order/problem 2 | # Score: 50 3 | 4 | 5 | from collections import Counter, OrderedDict 6 | 7 | 8 | class OrderedCounter(Counter, OrderedDict): 9 | pass 10 | 11 | 12 | ordered_counter = OrderedCounter(input() for _ in range(int(input()))) 13 | print(len(ordered_counter)) 14 | print(*ordered_counter.values()) 15 | -------------------------------------------------------------------------------- /Python/07. Collections/006. Collections deque().py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-collections-deque/problem 2 | # Score: 20 3 | 4 | 5 | from collections import deque 6 | 7 | 8 | d = deque() 9 | for _ in range(int(input())): 10 | line = input().split() 11 | if line[0] == 'append': 12 | d.append(line[1]) 13 | elif line[0] == 'pop': 14 | d.pop() 15 | elif line[0] == 'popleft': 16 | d.popleft() 17 | elif line[0] == 'appendleft': 18 | d.appendleft(line[1]) 19 | print(*d) 20 | -------------------------------------------------------------------------------- /Python/07. Collections/007. Company Logo.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/py-collections-deque/problem 2 | # Score: 30 3 | 4 | 5 | from collections import Counter, OrderedDict 6 | 7 | 8 | class OrderedCounter(Counter, OrderedDict): 9 | pass 10 | 11 | 12 | letters = OrderedCounter(sorted(input())).most_common(3) 13 | [print(*letter) for letter in letters] 14 | -------------------------------------------------------------------------------- /Python/07. Collections/008. Piling Up!.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/piling-up/problem 2 | # Score: 50 3 | 4 | 5 | from collections import deque 6 | 7 | 8 | for i in range(int(input())): 9 | _, n = input(), deque(map(int, input().split())) 10 | ans = True 11 | 12 | for j in range(len(n) - 1): 13 | if n[0] >= n[1]: 14 | n.popleft() 15 | elif n[-1] >= n[-2]: 16 | n.pop() 17 | else: 18 | ans = False 19 | break 20 | 21 | print('Yes' if ans else 'No') 22 | -------------------------------------------------------------------------------- /Python/08. Date and Time/001. Calendar Module.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/calendar-module/problem 2 | # Score: 10 3 | 4 | 5 | import calendar 6 | 7 | 8 | m, d, y = map(int, input().split()) 9 | print(calendar.day_name[calendar.weekday(y, m, d)].upper()) 10 | -------------------------------------------------------------------------------- /Python/08. Date and Time/002. Time Delta.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/python-time-delta/problem 2 | # Score: 30 3 | 4 | 5 | from datetime import datetime as dt 6 | 7 | fmt = '%a %d %b %Y %H:%M:%S %z' 8 | for _ in range(int(input())): 9 | time1 = dt.strptime(input(), fmt) 10 | time2 = dt.strptime(input(), fmt) 11 | print(int(abs((time1 - time2).total_seconds()))) 12 | -------------------------------------------------------------------------------- /Python/09. Errors and Exceptions/001. Exceptions.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/exceptions/problem 2 | # Score: 10 3 | 4 | 5 | for _ in range(int(input())): 6 | a, b = input().split() 7 | try: 8 | print(int(a) // int(b)) 9 | except BaseException as err: 10 | print("Error Code:", err) 11 | -------------------------------------------------------------------------------- /Python/09. Errors and Exceptions/002. Incorrect Regex.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/incorrect-regex/problem 2 | # Score: 20 3 | 4 | 5 | import re 6 | 7 | 8 | for _ in range(int(input())): 9 | try: 10 | print(bool(re.compile(input()))) 11 | except re.error: 12 | print('False') 13 | -------------------------------------------------------------------------------- /Python/16. Numpy/001. Arrays.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/np-arrays/problem 2 | # Score: 10 3 | 4 | 5 | import numpy 6 | 7 | 8 | def arrays(arr): 9 | return numpy.array(arr[::-1], float) 10 | 11 | 12 | arr = input().strip().split(' ') 13 | result = arrays(arr) 14 | print(result) 15 | -------------------------------------------------------------------------------- /Python/16. Numpy/002. Shape and Reshape.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/np-shape-reshape/problem 2 | # Score: 20 3 | 4 | 5 | import numpy as np 6 | 7 | 8 | array = np.array(list(map(int, input().split()))) 9 | print(array.reshape(3, 3)) 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | # Solutions to Hackerrank practice problems 4 | This repository contains 185 solutions to Hackerrank practice problems with Python 3 and Oracle SQL. 5 | 6 | Updated daily :) If it was helpful please press a star. 7 | 8 | [![GitHub last commit](https://img.shields.io/github/last-commit/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) 9 | [![GitHub commit activity the past week, 4 weeks, year](https://img.shields.io/github/commit-activity/y/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) 10 | [![GitHub repo size in bytes](https://img.shields.io/github/repo-size/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) 11 | [![GitHub stars](https://img.shields.io/github/stars/marinskiy/HackerrankPractice.svg)](https://github.com/marinskiy/HackerrankPractice) 12 | 13 | - Algorithms 14 | 01. Warmup 15 | - Solve Me First | [Problem](https://www.hackerrank.com/challenges/solve-me-first/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/001.%20Solve%20Me%20First.py) | Score: 1 16 | - Simple Array Sum | [Problem](https://www.hackerrank.com/challenges/simple-array-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/002.%20Simple%20Array%20Sum.py) | Score: 10 17 | - Compare the Triplets | [Problem](https://www.hackerrank.com/challenges/compare-the-triplets/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/003.%20Compare%20the%20Triplets.py) | Score: 10 18 | - A Very Big Sum | [Problem](https://www.hackerrank.com/challenges/a-very-big-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/004.%20A%20Very%20Big%20Sum.py) | Score: 10 19 | - Diagonal Difference | [Problem](https://www.hackerrank.com/challenges/diagonal-difference/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/005.%20Diagonal%20Difference.py) | Score: 10 20 | - Plus Minus | [Problem](https://www.hackerrank.com/challenges/plus-minus/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/006.%20Plus%20Minus.py) | Score: 10 21 | - Staircase | [Problem](https://www.hackerrank.com/challenges/staircase/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/007.%20Staircase.py) | Score: 10 22 | - Mini-Max Sum | [Problem](https://www.hackerrank.com/challenges/mini-max-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/008.%20Mini-Max%20Sum.py) | Score: 10 23 | - Birthday Cake Candles | [Problem](https://www.hackerrank.com/challenges/birthday-cake-candles/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/009.%20Birthday%20Cake%20Candles.py) | Score: 10 24 | - Time Conversion | [Problem](https://www.hackerrank.com/challenges/time-conversion/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/01.%20Warmup/010.%20Time%20Conversion.py) | Score: 15 25 | 02. Implementation 26 | - Grading Students | [Problem](https://www.hackerrank.com/challenges/grading/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/001.%20Grading%20Students.py) | Score: 10 27 | - Apple and Orange | [Problem](https://www.hackerrank.com/challenges/apple-and-orange/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/002.%20Apple%20and%20Orange.py) | Score: 10 28 | - Kangaroo | [Problem](https://www.hackerrank.com/challenges/kangaroo/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/003.%20Kangaroo.py) | Score: 10 29 | - Between Two Sets | [Problem](https://www.hackerrank.com/challenges/between-two-sets/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/004.%20Between%20Two%20Sets.py) | Score: 10 30 | - Breaking the Records | [Problem](https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/005.%20Breaking%20the%20Records.py) | Score: 10 31 | - Birthday Chocolate | [Problem](https://www.hackerrank.com/challenges/the-birthday-bar/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/006.%20Birthday%20Chocolate.py) | Score: 10 32 | - Electronics Shop | [Problem](https://www.hackerrank.com/challenges/electronics-shop/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/013.%20Electronics%20Shop.py) | Score: 15 33 | - Cats and a Mouse | [Problem](https://www.hackerrank.com/challenges/cats-and-a-mouse/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/014.%20Cats%20and%20a%20Mouse.py) | Score: 15 34 | - Forming a Magic Square | [Problem](https://www.hackerrank.com/challenges/magic-square-forming) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/015.%20Forming%20a%20Magic%20Square.py) | Score: 20 35 | - Picking Numbers | [Problem](https://www.hackerrank.com/challenges/picking-numbers) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/016.%20Picking%20Numbers.py) | Score: 20 36 | - Climbing the Leaderboard | [Problem](https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/017.%20Climbing%20the%20Leaderboard.py) | Score: 20 37 | - The Hurdle Race | [Problem](https://www.hackerrank.com/challenges/the-hurdle-race/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/02.%20Implementation/018.%20The%20Hurdle%20Race.py) | Score: 15 38 | 04. Sorting 39 | - Intro to Tutorial Challenges | [Problem](https://www.hackerrank.com/challenges/tutorial-intro/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/04.%20Sorting/001.%20Intro%20to%20Tutorial%20Challenges.py) | Score: 30 40 | - Big Sorting | [Problem](https://www.hackerrank.com/challenges/big-sorting/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/04.%20Sorting/002.%20Big%20Sorting.py) | Score: 20 41 | 05. Search 42 | - Pairs | [Problem](https://www.hackerrank.com/challenges/pairs/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/05.%20Search/007.%20Pairs.py) | Score: 50 43 | 07. Greedy 44 | - Minimum Absolute Difference in an Array | [Problem](https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/07.%20Greedy/001.%20Minimum%20Absolute%20Difference%20in%20an%20Array.py) | Score: 15 45 | - Marc's Cakewalk | [Problem](https://www.hackerrank.com/challenges/marcs-cakewalk/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/07.%20Greedy/002.%20Marc's%20Cakewalk.py) | Score: 15 46 | - Permuting Two Arrays | [Problem](https://www.hackerrank.com/challenges/two-arrays/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/07.%20Greedy/014.%20Permuting%20Two%20Arrays.py) | Score: 40 47 | 08. Dynamic Programming 48 | - The Coin Change Problem | [Problem](https://www.hackerrank.com/challenges/coin-change/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/08.%20Dynamic%20Programming/001.%20The%20Coin%20Change%20Problem.py) | Score: 60 49 | - Equal | [Problem](https://www.hackerrank.com/challenges/equal/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/08.%20Dynamic%20Programming/002.%20Equal.py) | Score: 30 50 | - Sherlock and Cost | [Problem](https://www.hackerrank.com/challenges/sherlock-and-cost/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/08.%20Dynamic%20Programming/003.%20Sherlock%20and%20Cost.py) | Score: 50 51 | - Construct the Array | [Problem](https://www.hackerrank.com/challenges/construct-the-array/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/08.%20Dynamic%20Programming/004.%20Construct%20the%20Array.py) | Score: 35 52 | - Fibonacci Modified | [Problem](https://www.hackerrank.com/challenges/fibonacci-modified/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Algorithms/08.%20Dynamic%20Programming/008.%20Fibonacci%20Modified.py) | Score: 45 53 | - Artificial Intelligence 54 | 01. Statistics and Machine Learning 55 | Statistics and Machine Learning 56 | - Laptop Battery Life | [Problem](https://www.hackerrank.com/challenges/battery/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Artificial%20Intelligence/Statistics%20and%20Machine%20Learning/001.%20Laptop%20Battery%20Life.py) | Score: 10 57 | - C++ 58 | 01. Introduction 59 | - Say Hello, World! With Cpp | [Problem](https://www.hackerrank.com/challenges/arrays-ds/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/C++/01.%20Introduction/001.%20Say%20Hello,%20World!%20With%20Cpp.cpp) | Score: 10 60 | - Data Structures 61 | 01. Arrays 62 | - Arrays - DS | [Problem](https://www.hackerrank.com/challenges/arrays-ds/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Data%20Structures/01.%20Arrays/001.%20Arrays%20-%20DS.py) | Score: 10 63 | - Interview Preparation Kit - CPP 64 | 01. Warm-up Challenges 65 | - Sock Merchant | [Problem](https://www.hackerrank.com/challenges/sock-merchant/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/01.%20Warm-up%20Challenges/001.%20Sock%20Merchant.cpp) | Score: 10 66 | - Counting Valleys | [Problem](https://www.hackerrank.com/challenges/counting-valleys/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/01.%20Warm-up%20Challenges/002.%20Counting%20Valleys.cpp) | Score: 15 67 | - Jumping on the Clouds | [Problem](https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/01.%20Warm-up%20Challenges/003.%20Jumping%20on%20the%20Clouds.cpp) | Score: 20 68 | - Repeated String | [Problem](https://www.hackerrank.com/challenges/repeated-string/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/01.%20Warm-up%20Challenges/004.%20Repeated%20String.cpp) | Score: 20 69 | 02. Arrays 70 | - 2D Array - DS | [Problem](https://www.hackerrank.com/challenges/2d-array/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/02.%20Arrays/001.%202D%20Array%20-%20DS.cpp) | Score: 15 71 | - Arrays - Left Rotation | [Problem](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/02.%20Arrays/002.%20Arrays%20-%20Left%20Rotation.cpp) | Score: 20 72 | - New Year Chaos | [Problem](https://www.hackerrank.com/challenges/new-year-chaos/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20CPP/02.%20Arrays/003.%20New%20Year%20Chaos.cpp) | Score: 40 73 | - Interview Preparation Kit - Python 74 | 01. Warm-up Challenges 75 | - Sock Merchant | [Problem](https://www.hackerrank.com/challenges/sock-merchant/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/01.%20Warm-up%20Challenges/001.%20Sock%20Merchant.py) | Score: 10 76 | - Counting Valleys | [Problem](https://www.hackerrank.com/challenges/counting-valleys/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/01.%20Warm-up%20Challenges/002.%20Counting%20Valleys.py) | Score: 15 77 | - Jumping on the Clouds | [Problem](https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/01.%20Warm-up%20Challenges/003.%20Jumping%20on%20the%20Clouds.py) | Score: 20 78 | - Repeated String | [Problem](https://www.hackerrank.com/challenges/repeated-string/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/01.%20Warm-up%20Challenges/004.%20Repeated%20String.py) | Score: 20 79 | 02. Arrays 80 | - Arrays - Left Rotation | [Problem](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/02.%20Arrays/001.%20Arrays%20-%20Left%20Rotation.py) | Score: 20 81 | - 2D Array - DS | [Problem](https://www.hackerrank.com/challenges/2d-array/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/02.%20Arrays/002.%202D%20Array%20-%20DS.py) | Score: 15 82 | - New Year Chaos | [Problem](https://www.hackerrank.com/challenges/new-year-chaos/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/02.%20Arrays/003.%20New%20Year%20Chaos.py) | Score: 40 83 | - Minimum Swaps 2 | [Problem](https://www.hackerrank.com/challenges/minimum-swaps-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/02.%20Arrays/004.%20Minimum%20Swaps%202.py) | Score: 40 84 | - Array Manipulation | [Problem](https://www.hackerrank.com/challenges/crush/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/02.%20Arrays/005.%20Array%20Manipulation.py) | Score: 60 85 | 03. Dictionaries and Hashmaps 86 | - Hash Tables - Ransom Note | [Problem](https://www.hackerrank.com/challenges/ctci-ransom-note/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/03.%20Dictionaries%20and%20Hashmaps/001.%20Hash%20Tables%20-%20Ransom%20Note.py) | Score: 25 87 | - Two Strings | [Problem](https://www.hackerrank.com/challenges/two-strings/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/03.%20Dictionaries%20and%20Hashmaps/002.%20Two%20Strings.py) | Score: 25 88 | - Count Triplets | [Problem](https://www.hackerrank.com/challenges/count-triplets-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/03.%20Dictionaries%20and%20Hashmaps/003.%20Count%20Triplets.py) | Score: 25 89 | - Frequency Queries | [Problem](https://www.hackerrank.com/challenges/frequency-queries/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/03.%20Dictionaries%20and%20Hashmaps/004.%20Frequency%20Queries.py) | Score: 40 90 | - Sherlock and Anagrams | [Problem](https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/03.%20Dictionaries%20and%20Hashmaps/005.%20Sherlock%20and%20Anagrams.py) | Score: 50 91 | 04. Sorting 92 | - Sorting - Bubble Sort | [Problem](https://www.hackerrank.com/challenges/ctci-bubble-sort/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/04.%20Sorting/001.%20Sorting%20-%20Bubble%20Sort.py) | Score: 30 93 | - Mark and Toys | [Problem](https://www.hackerrank.com/challenges/mark-and-toys/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/04.%20Sorting/002.%20Mark%20and%20Toys.py) | Score: 35 94 | 07. Search 95 | - Hash Tables - Ice Cream Parlor | [Problem](https://www.hackerrank.com/challenges/ctci-ice-cream-parlor/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/07.%20Search/001.%20Hash%20Tables%20-%20Ice%20Cream%20Parlor.py) | Score: 35 96 | - Minimum Time Required | [Problem](https://www.hackerrank.com/challenges/minimum-time-required/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/07.%20Search/002.%20Minimum%20Time%20Required.py) | Score: 35 97 | - Triple sum | [Problem](https://www.hackerrank.com/challenges/triple-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/07.%20Search/003.%20Triple%20sum.py) | Score: 40 98 | 08. Dynamic Programming 99 | - Max Array Sum | [Problem](https://www.hackerrank.com/challenges/max-array-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Interview%20Preparation%20Kit%20-%20Python/08.%20Dynamic%20Programming/001.%20Max%20Array%20Sum.py) | Score: 20 100 | - Python 101 | 01. Introduction 102 | - Say Hello, World! With Python | [Problem](https://www.hackerrank.com/challenges/py-hello-world/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/001.%20Say%20Hello,%20World!%20With%20Python.py) | Score: 5 103 | - Python If-Else | [Problem](https://www.hackerrank.com/challenges/py-if-else/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/002.%20Python%20If-Else.py) | Score: 10 104 | - Arithmetic Operators | [Problem](https://www.hackerrank.com/challenges/python-arithmetic-operators/submissions/code/70402456) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/003.%20Arithmetic%20Operators.py) | Score: 10 105 | - Python Division | [Problem](https://www.hackerrank.com/challenges/python-division/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/004.%20Python%20Division.py) | Score: 10 106 | - Loops | [Problem](https://www.hackerrank.com/challenges/python-loops/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/005.%20Loops.py) | Score: 10 107 | - Write a function | [Problem](https://www.hackerrank.com/challenges/write-a-function/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/006.%20Write%20a%20function.py) | Score: 10 108 | - Print Function | [Problem](https://www.hackerrank.com/challenges/python-print/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/01.%20Introduction/007.%20Print%20Function.py) | Score: 20 109 | 02. Basic Data Types 110 | - List Comprehensions | [Problem](https://www.hackerrank.com/challenges/list-comprehensions/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/001.%20List%20Comprehensions.py) | Score: 10 111 | - Find the Runner-Up Score! | [Problem](https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/002.%20Find%20the%20Runner-Up%20Score!.py) | Score: 10 112 | - Nested Lists | [Problem](https://www.hackerrank.com/challenges/nested-list/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/003.%20Nested%20Lists.py) | Score: 10 113 | - Finding the percentage | [Problem](https://www.hackerrank.com/challenges/finding-the-percentage/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/004.%20Finding%20the%20percentage.py) | Score: 10 114 | - Lists | [Problem](https://www.hackerrank.com/challenges/python-lists/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/005.%20Lists.py) | Score: 10 115 | - Tuples | [Problem](https://www.hackerrank.com/challenges/python-tuples/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/02.%20Basic%20Data%20Types/006.%20Tuples.py) | Score: 10 116 | 03. Strings 117 | - sWAP cASE | [Problem](https://www.hackerrank.com/challenges/swap-case/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/001.%20sWAP%20cASE.py) | Score: 10 118 | - String Split and Join | [Problem](https://www.hackerrank.com/challenges/python-string-split-and-join/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/002.%20String%20Split%20and%20Join.py) | Score: 10 119 | - What's Your Name | [Problem](https://www.hackerrank.com/challenges/whats-your-name/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/003.%20What's%20Your%20Name.py) | Score: 10 120 | - Mutations | [Problem](https://www.hackerrank.com/challenges/python-mutations/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/004.%20Mutations.py) | Score: 10 121 | - Find a string | [Problem](https://www.hackerrank.com/challenges/find-a-string/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/005.%20Find%20a%20string.py) | Score: 10 122 | - String Validators | [Problem](https://www.hackerrank.com/challenges/string-validators/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/006.%20String%20Validators.py) | Score: 10 123 | - Text Alignment | [Problem](https://www.hackerrank.com/challenges/text-alignment/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/007.%20Text%20Alignment.py) | Score: 10 124 | - Text Wrap | [Problem](https://www.hackerrank.com/challenges/text-wrap/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/008.%20Text%20Wrap.py) | Score: 10 125 | - Designer Door Mat | [Problem](https://www.hackerrank.com/challenges/designer-door-mat/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/009.%20Designer%20Door%20Mat.py) | Score: 10 126 | - String Formatting | [Problem](https://www.hackerrank.com/challenges/python-string-formatting/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/010.%20String%20Formatting.py) | Score: 10 127 | - Capitalize! | [Problem](https://www.hackerrank.com/challenges/capitalize/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/03.%20Strings/011.%20Capitalize!.py) | Score: 20 128 | 04. Sets 129 | - Introduction to Sets | [Problem](https://www.hackerrank.com/challenges/py-introduction-to-sets/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/001.%20Introduction%20to%20Sets.py) | Score: 10 130 | - No Idea! | [Problem](https://www.hackerrank.com/challenges/no-idea/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/002.%20No%20Idea!.py) | Score: 50 131 | - Symmetric Difference | [Problem](https://www.hackerrank.com/challenges/symmetric-difference/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/003.%20Symmetric%20Difference.py) | Score: 10 132 | - Set add() | [Problem](https://www.hackerrank.com/challenges/py-set-add/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/004.%20Set%20add().py) | Score: 10 133 | - Set discard() remove() pop() | [Problem](https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/005.%20Set%20discard()%20remove()%20pop().py) | Score: 10 134 | - Set union() Operation | [Problem](https://www.hackerrank.com/challenges/py-set-union/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/006.%20Set%20union()%20Operation.py) | Score: 10 135 | - Set intersection() Operation | [Problem](https://www.hackerrank.com/challenges/py-set-intersection-operation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/007.%20Set%20intersection()%20Operation.py) | Score: 10 136 | - Set difference() Operation | [Problem](https://www.hackerrank.com/challenges/py-set-difference-operation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/008.%20Set%20difference()%20Operation.py) | Score: 10 137 | - Set symmetric_difference() Operation | [Problem](https://www.hackerrank.com/challenges/py-set-symmetric-difference-operation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/009.%20Set%20symmetric_difference()%20Operation.py) | Score: 10 138 | - Set Mutations | [Problem](https://www.hackerrank.com/challenges/py-set-mutations/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/010.%20Set%20Mutations.py) | Score: 10 139 | - The Captain's Room | [Problem](https://www.hackerrank.com/challenges/py-the-captains-room/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/011.%20The%20Captain's%20Room.py) | Score: 10 140 | - Check Subset | [Problem](https://www.hackerrank.com/challenges/py-check-subset/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/012.%20Check%20Subset.py) | Score: 10 141 | - Check Strict Superset | [Problem](https://www.hackerrank.com/challenges/py-check-strict-superset/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/04.%20Sets/013.%20Check%20Strict%20Superset.py) | Score: 10 142 | 06. Itertools 143 | - itertoolsproduct() | [Problem](https://www.hackerrank.com/challenges/itertools-product/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/001.%20itertools.product().py) | Score: 10 144 | - itertoolscombinations() | [Problem](https://www.hackerrank.com/challenges/itertools-combinations/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/002.%20itertools.combinations().py) | Score: 10 145 | - itertoolspermutations() | [Problem](https://www.hackerrank.com/challenges/itertools-permutations/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/003.%20itertools.permutations().py) | Score: 10 146 | - itertoolscombinations_with_replacement() | [Problem](https://www.hackerrank.com/challenges/itertools-combinations-with-replacement/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/004.%20itertools.combinations_with_replacement().py) | Score: 10 147 | - Compress the String! | [Problem](https://www.hackerrank.com/challenges/compress-the-string/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/005.%20Compress%20the%20String!.py) | Score: 20 148 | - Iterables and Iterators | [Problem](https://www.hackerrank.com/challenges/iterables-and-iterators/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/006.%20Iterables%20and%20Iterators.py) | Score: 40 149 | - Maximize It! | [Problem](https://www.hackerrank.com/challenges/maximize-it/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/06.%20Itertools/007.%20Maximize%20It!.py) | Score: 50 150 | 07. Collections 151 | - collectionsCounter() | [Problem](https://www.hackerrank.com/challenges/collections-counter/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/001.%20collections.Counter().py) | Score: 10 152 | - DefaultDict Tutorial | [Problem](https://www.hackerrank.com/challenges/defaultdict-tutorial/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/002.%20DefaultDict%20Tutorial.py) | Score: 20 153 | - Collections namedtuple() | [Problem](https://www.hackerrank.com/challenges/py-collections-namedtuple/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/003.%20Collections%20namedtuple().py) | Score: 20 154 | - Collections OrderedDict() | [Problem](https://www.hackerrank.com/challenges/py-collections-ordereddict/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/004.%20Collections%20OrderedDict().py) | Score: 20 155 | - Word Order | [Problem](https://www.hackerrank.com/challenges/word-order/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/005.%20Word%20Order.py) | Score: 50 156 | - Collections deque() | [Problem](https://www.hackerrank.com/challenges/py-collections-deque/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/006.%20Collections%20deque().py) | Score: 20 157 | - Company Logo | [Problem](https://www.hackerrank.com/challenges/py-collections-deque/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/007.%20Company%20Logo.py) | Score: 30 158 | - Piling Up! | [Problem](https://www.hackerrank.com/challenges/piling-up/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/07.%20Collections/008.%20Piling%20Up!.py) | Score: 50 159 | 08. Date and Time 160 | - Calendar Module | [Problem](https://www.hackerrank.com/challenges/calendar-module/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/08.%20Date%20and%20Time/001.%20Calendar%20Module.py) | Score: 10 161 | - Time Delta | [Problem](https://www.hackerrank.com/challenges/python-time-delta/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/08.%20Date%20and%20Time/002.%20Time%20Delta.py) | Score: 30 162 | 09. Errors and Exceptions 163 | - Exceptions | [Problem](https://www.hackerrank.com/challenges/exceptions/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/09.%20Errors%20and%20Exceptions/001.%20Exceptions.py) | Score: 10 164 | - Incorrect Regex | [Problem](https://www.hackerrank.com/challenges/incorrect-regex/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/09.%20Errors%20and%20Exceptions/002.%20Incorrect%20Regex.py) | Score: 20 165 | 16. Numpy 166 | - Arrays | [Problem](https://www.hackerrank.com/challenges/np-arrays/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/16.%20Numpy/001.%20Arrays.py) | Score: 10 167 | - Shape and Reshape | [Problem](https://www.hackerrank.com/challenges/np-shape-reshape/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Python/16.%20Numpy/002.%20Shape%20and%20Reshape.py) | Score: 20 168 | - SQL 169 | 01. Basic Select 170 | - Revising the Select Query I | [Problem](https://www.hackerrank.com/challenges/revising-the-select-query/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/001.%20Revising%20the%20Select%20Query%20I.sql) | Score: 10 171 | - Revising the Select Query II | [Problem](https://www.hackerrank.com/challenges/revising-the-select-query-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/002.%20Revising%20the%20Select%20Query%20II.sql) | Score: 10 172 | - Select All | [Problem](https://www.hackerrank.com/challenges/select-all-sql/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/003.%20Select%20All.sql) | Score: 10 173 | - Select By ID | [Problem](https://www.hackerrank.com/challenges/select-by-id/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/004.%20Select%20By%20ID.sql) | Score: 10 174 | - Japanese Cities' Attributes | [Problem](https://www.hackerrank.com/challenges/japanese-cities-attributes/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/005.%20Japanese%20Cities'%20Attributes.sql) | Score: 10 175 | - Japanese Cities' Names | [Problem](https://www.hackerrank.com/challenges/japanese-cities-name/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/006.%20Japanese%20Cities'%20Names.sql) | Score: 10 176 | - Weather Observation Station 1 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/007.%20Weather%20Observation%20Station%201.sql) | Score: 15 177 | - Weather Observation Station 3 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-3/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/008.%20Weather%20Observation%20Station%203.sql) | Score: 10 178 | - Weather Observation Station 4 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-4/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/009.%20Weather%20Observation%20Station%204.sql) | Score: 10 179 | - Weather Observation Station 5 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-5/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/010.%20Weather%20Observation%20Station%205.sql) | Score: 30 180 | - Weather Observation Station 6 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-6/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/011.%20Weather%20Observation%20Station%206.sql) | Score: 10 181 | - Weather Observation Station 7 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-7/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/012.%20Weather%20Observation%20Station%207.sql) | Score: 10 182 | - Weather Observation Station 8 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-8/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/013.%20Weather%20Observation%20Station%208.sql) | Score: 15 183 | - Weather Observation Station 9 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-9/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/014.%20Weather%20Observation%20Station%209.sql) | Score: 10 184 | - Weather Observation Station 10 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-10/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/015.%20Weather%20Observation%20Station%2010.sql) | Score: 10 185 | - Weather Observation Station 11 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-11/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/016.%20Weather%20Observation%20Station%2011.sql) | Score: 15 186 | - Weather Observation Station 12 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-11/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/017.%20Weather%20Observation%20Station%2012.sql) | Score: 15 187 | - Higher Than 75 Marks | [Problem](https://www.hackerrank.com/challenges/more-than-75-marks/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/018.%20Higher%20Than%2075%20Marks.sql) | Score: 15 188 | - Employee Names | [Problem](https://www.hackerrank.com/challenges/name-of-employees/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/019.%20Employee%20Names.sql) | Score: 10 189 | - Employee Salaries | [Problem](https://www.hackerrank.com/challenges/salary-of-employees/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/01.%20Basic%20Select/020.%20Employee%20Salaries.sql) | Score: 10 190 | 02. Advanced Select 191 | - Type of Triangle | [Problem](https://www.hackerrank.com/challenges/what-type-of-triangle/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/02.%20Advanced%20Select/001.%20Type%20of%20Triangle.sql) | Score: 20 192 | - The PADS | [Problem](https://www.hackerrank.com/challenges/the-pads/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/02.%20Advanced%20Select/002.%20The%20PADS.sql) | Score: 30 193 | - Binary Tree Nodes | [Problem](https://www.hackerrank.com/challenges/binary-search-tree-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/02.%20Advanced%20Select/004.%20Binary%20Tree%20Nodes.sql) | Score: 30 194 | 03. Aggregation 195 | - Revising Aggregations - The Count Function | [Problem](https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/001.%20Revising%20Aggregations%20-%20The%20Count%20Function.sql) | Score: 10 196 | - Revising Aggregations - The Sum Function | [Problem](https://www.hackerrank.com/challenges/revising-aggregations-sum/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/002.%20Revising%20Aggregations%20-%20The%20Sum%20Function.sql) | Score: 10 197 | - Revising Aggregations - Averages | [Problem](https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/003.%20Revising%20Aggregations%20-%20Averages.sql) | Score: 10 198 | - Average Population | [Problem](https://www.hackerrank.com/challenges/average-population/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/004.%20Average%20Population.sql) | Score: 10 199 | - Japan Population | [Problem](https://www.hackerrank.com/challenges/japan-population/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/005.%20Japan%20Population.sql) | Score: 10 200 | - Population Density Difference | [Problem](https://www.hackerrank.com/challenges/population-density-difference/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/006.%20Population%20Density%20Difference.sql) | Score: 10 201 | - The Blunder | [Problem](https://www.hackerrank.com/challenges/the-blunder/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/007.%20The%20Blunder.sql) | Score: 15 202 | - Top Earners | [Problem](https://www.hackerrank.com/challenges/earnings-of-employees/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/008.%20Top%20Earners.sql) | Score: 20 203 | - Weather Observation Station 2 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/009.%20Weather%20Observation%20Station%202.sql) | Score: 15 204 | - Weather Observation Station 13 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-13/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/010.%20Weather%20Observation%20Station%2013.sql) | Score: 10 205 | - Weather Observation Station 14 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-14/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/011.%20Weather%20Observation%20Station%2014.sql) | Score: 10 206 | - Weather Observation Station 15 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-15/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/012.%20Weather%20Observation%20Station%2015.sql) | Score: 15 207 | - Weather Observation Station 16 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-16/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/013.%20Weather%20Observation%20Station%2016.sql) | Score: 10 208 | - Weather Observation Station 17 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-17/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/014.%20Weather%20Observation%20Station%2017.sql) | Score: 15 209 | - Weather Observation Station 18 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-18/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/015.%20Weather%20Observation%20Station%2018.sql) | Score: 25 210 | - Weather Observation Station 19 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-19/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/016.%20Weather%20Observation%20Station%2019.sql) | Score: 30 211 | - Weather Observation Station 20 | [Problem](https://www.hackerrank.com/challenges/weather-observation-station-20/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/03.%20Aggregation/017.%20Weather%20Observation%20Station%2020.sql) | Score: 40 212 | 04. Basic Join 213 | - Asian Population | [Problem](https://www.hackerrank.com/challenges/asian-population/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/04.%20Basic%20Join/001.%20Asian%20Population.sql) | Score: 10 214 | - African Cities | [Problem](https://www.hackerrank.com/challenges/african-cities/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/04.%20Basic%20Join/002.%20African%20Cities.sql) | Score: 10 215 | - Average Population of Each Continent | [Problem](https://www.hackerrank.com/challenges/average-population-of-each-continent/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/04.%20Basic%20Join/003.%20Average%20Population%20of%20Each%20Continent.sql) | Score: 10 216 | - The Report | [Problem](https://www.hackerrank.com/challenges/the-report/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/SQL/04.%20Basic%20Join/004.%20The%20Report.sql) | Score: 20 217 | - Tutorials 218 | 01. 10 Days of Statistics 219 | - Day 0 - Mean, Median, and Mode | [Problem](https://www.hackerrank.com/challenges/s10-basic-statistics/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/001.%20Day%200%20-%20Mean,%20Median,%20and%20Mode.py) | Score: 30 220 | - Day 0 - Weighted Mean | [Problem](https://www.hackerrank.com/challenges/s10-weighted-mean/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/002.%20Day%200%20-%20Weighted%20Mean.py) | Score: 30 221 | - Day 1 - Quartiles | [Problem](https://www.hackerrank.com/challenges/s10-quartiles/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/003.%20Day%201%20-%20Quartiles.py) | Score: 30 222 | - Day 1 - Interquartile Range | [Problem](https://www.hackerrank.com/challenges/s10-interquartile-range/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/004.%20Day%201%20-%20Interquartile%20Range.py) | Score: 30 223 | - Day 1 - Standard Deviation | [Problem](https://www.hackerrank.com/challenges/s10-standard-deviation/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/005.%20Day%201%20-%20Standard%20Deviation.py) | Score: 30 224 | - Day 4 - Binomial Distribution I | [Problem](https://www.hackerrank.com/challenges/s10-binomial-distribution-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/006.%20Day%204%20-%20Binomial%20Distribution%20I.py) | Score: 30 225 | - Day 4 - Binomial Distribution II | [Problem](https://www.hackerrank.com/challenges/s10-binomial-distribution-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/007.%20Day%204%20-%20Binomial%20Distribution%20II.py) | Score: 30 226 | - Day 4 - Geometric Distribution I | [Problem](https://www.hackerrank.com/challenges/s10-geometric-distribution-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/008.%20Day%204%20-%20Geometric%20Distribution%20I.py) | Score: 30 227 | - Day 4 - Geometric Distribution II | [Problem](https://www.hackerrank.com/challenges/s10-geometric-distribution-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/009.%20Day%204%20-%20Geometric%20Distribution%20II.py) | Score: 30 228 | - Day 5 - Poisson Distribution I | [Problem](https://www.hackerrank.com/challenges/s10-poisson-distribution-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/010.%20Day%205%20-%20Poisson%20Distribution%20I.py) | Score: 30 229 | - Day 5 - Poisson Distribution II | [Problem](https://www.hackerrank.com/challenges/s10-poisson-distribution-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/011.%20Day%205%20-%20Poisson%20Distribution%20II.py) | Score: 30 230 | - Day 5 - Normal Distribution I | [Problem](https://www.hackerrank.com/challenges/s10-normal-distribution-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/012.%20Day%205%20-%20Normal%20Distribution%20I.py) | Score: 30 231 | - Day 5 - Normal Distribution II | [Problem](https://www.hackerrank.com/challenges/s10-normal-distribution-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/013.%20Day%205%20-%20Normal%20Distribution%20II.py) | Score: 30 232 | - Day 6 - The Central Limit Theorem I | [Problem](https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-1/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/014.%20Day%206%20-%20The%20Central%20Limit%20Theorem%20I.py) | Score: 30 233 | - Day 6 - The Central Limit Theorem II | [Problem](https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-2/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/015.%20Day%206%20-%20The%20Central%20Limit%20Theorem%20II.py) | Score: 30 234 | - Day 6 - The Central Limit Theorem III | [Problem](https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-3/problem) | [Solution](https://github.com/marinskiy/HackerrankPractice/blob/master/Tutorials/01.%2010%20Days%20of%20Statistics/016.%20Day%206%20-%20The%20Central%20Limit%20Theorem%20III.py) | Score: 30 235 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/001. Revising the Select Query I.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-the-select-query/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE 8 | COUNTRYCODE = 'USA' 9 | AND POPULATION > 100000; 10 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/002. Revising the Select Query II.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-the-select-query-2/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT NAME 6 | FROM CITY 7 | WHERE 8 | COUNTRYCODE = 'USA' 9 | AND POPULATION > 120000; 10 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/003. Select All.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/select-all-sql/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT * 6 | FROM CITY; 7 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/004. Select By ID.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/select-by-id/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE ID = 1661; 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/005. Japanese Cities' Attributes.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japanese-cities-attributes/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT * 6 | FROM CITY 7 | WHERE COUNTRYCODE = 'JPN'; 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/006. Japanese Cities' Names.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japanese-cities-name/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT NAME 6 | FROM CITY 7 | WHERE COUNTRYCODE = 'JPN'; 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/007. Weather Observation Station 1.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-1/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT CITY, STATE FROM STATION; 6 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/008. Weather Observation Station 3.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-3/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE MOD(ID, 2) = 0; 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/009. Weather Observation Station 4.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-4/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT COUNT(CITY) - COUNT(DISTINCT CITY) 6 | FROM STATION; 7 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/010. Weather Observation Station 5.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-5/problem 2 | -- # Score: 30 3 | 4 | 5 | SELECT * 6 | FROM 7 | (SELECT CITY, LENGTH(CITY) 8 | FROM STATION 9 | ORDER BY LENGTH(CITY), CITY) 10 | WHERE ROWNUM = 1 11 | UNION 12 | SELECT * 13 | FROM 14 | (SELECT CITY, LENGTH(CITY) 15 | FROM STATION 16 | ORDER BY LENGTH(CITY) DESC, CITY) 17 | WHERE ROWNUM = 1; 18 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/011. Weather Observation Station 6.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-6/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE REGEXP_LIKE(City, '^[AEIOU]'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/012. Weather Observation Station 7.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-7/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE REGEXP_LIKE(City, '[aeiou]$'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/013. Weather Observation Station 8.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-8/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE REGEXP_LIKE(City, '^[AEIOU].*[aeiou]$'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/014. Weather Observation Station 9.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-9/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE REGEXP_LIKE(City, '^[^AEIOU]'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/015. Weather Observation Station 10.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-10/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT DISTINCT City 6 | FROM Station 7 | WHERE REGEXP_LIKE(City, '[^aeiou]$'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/016. Weather Observation Station 11.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-11/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT DISTINCT City FROM Station 6 | WHERE REGEXP_LIKE(City, '^[^AEIOU]|[^aeiou]$'); 7 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/017. Weather Observation Station 12.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-11/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT DISTINCT City 6 | FROM Station 7 | WHERE REGEXP_LIKE(City, '^[^AEIOU].*[^aeiou]$'); 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/018. Higher Than 75 Marks.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/more-than-75-marks/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT Name 6 | FROM Students 7 | WHERE Marks > 75 8 | ORDER BY SUBSTR(Name, - 3), Id ASC; 9 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/019. Employee Names.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/name-of-employees/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT Name 6 | FROM Employee 7 | ORDER BY Name; 8 | -------------------------------------------------------------------------------- /SQL/01. Basic Select/020. Employee Salaries.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/salary-of-employees/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT Name 6 | FROM Employee 7 | WHERE Salary > 2000 AND Months < 10 8 | ORDER BY Employee_id; 9 | -------------------------------------------------------------------------------- /SQL/02. Advanced Select/001. Type of Triangle.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/what-type-of-triangle/problem 2 | -- # Score: 20 3 | 4 | 5 | SELECT 6 | CASE 7 | WHEN A >= (B + C) OR B >= (A + C) OR C >= (A + B) THEN 'Not A Triangle' 8 | WHEN A = B AND A = C THEN 'Equilateral' 9 | WHEN A = B OR B = C OR A = C THEN 'Isosceles' 10 | ELSE 'Scalene' 11 | END 12 | FROM TRIANGLES; 13 | -------------------------------------------------------------------------------- /SQL/02. Advanced Select/002. The PADS.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-pads/problem 2 | -- # Score: 30 3 | 4 | 5 | SELECT Name || '(' || SUBSTR(Occupation, 1, 1) || ')' 6 | FROM OCCUPATIONS 7 | ORDER BY Name; 8 | 9 | SELECT 'There are a total of ' || Count(Name) || ' ' || LOWER(Occupation) || 's.' 10 | FROM Occupations 11 | GROUP BY Occupation 12 | ORDER BY Count(Name), Occupation; 13 | -------------------------------------------------------------------------------- /SQL/02. Advanced Select/004. Binary Tree Nodes.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/binary-search-tree-1/problem 2 | -- # Score: 30 3 | 4 | 5 | SELECT N, 6 | CASE 7 | WHEN P IS NULL THEN 'Root' 8 | WHEN N IN (SELECT P FROM BST) THEN 'Inner' 9 | ELSE 'Leaf' 10 | END 11 | FROM BST 12 | ORDER BY N; 13 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/001. Revising Aggregations - The Count Function.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT COUNT(*) 6 | FROM City 7 | WHERE Population > 100000; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/002. Revising Aggregations - The Sum Function.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-sum/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT SUM(Population) 6 | FROM City 7 | WHERE District = 'California'; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/003. Revising Aggregations - Averages.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT AVG(Population) 6 | FROM City 7 | WHERE District = 'California'; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/004. Average Population.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/average-population/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT FLOOR(AVG(Population)) 6 | FROM City; 7 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/005. Japan Population.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/japan-population/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT SUM(Population) 6 | FROM City 7 | WHERE CountryCode = 'JPN'; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/006. Population Density Difference.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/population-density-difference/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT MAX(Population) - MIN(Population) 6 | FROM City; 7 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/007. The Blunder.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-blunder/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT CEIL(AVG(Salary) - AVG(REPLACE(Salary, '0', ''))) 6 | FROM EMPLOYEES; 7 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/008. Top Earners.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/earnings-of-employees/problem 2 | -- # Score: 20 3 | 4 | 5 | SELECT * 6 | FROM ( 7 | SELECT Months * Salary, COUNT(*) 8 | FROM Employee 9 | GROUP BY (Months * Salary) 10 | ORDER BY Months * Salary DESC 11 | ) 12 | WHERE ROWNUM = 1; 13 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/009. Weather Observation Station 2.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-2/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT ROUND(SUM(Lat_N), 2), ROUND(SUM(Long_W), 2) 6 | FROM Station; 7 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/010. Weather Observation Station 13.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-13/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT ROUND(SUM(Lat_N), 4) 6 | FROM STATION 7 | WHERE Lat_N > 38.7880 AND Lat_N < 137.2345; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/011. Weather Observation Station 14.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-14/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT ROUND(MAX(Lat_N), 4) 6 | FROM Station 7 | WHERE Lat_N < 137.2345; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/012. Weather Observation Station 15.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-15/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT ROUND(Long_W, 4) 6 | FROM ( 7 | SELECT Long_W 8 | FROM Station 9 | WHERE Lat_N < 137.2345 10 | ORDER BY Lat_N DESC 11 | ) 12 | WHERE ROWNUM = 1; 13 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/013. Weather Observation Station 16.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-16/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT ROUND(MIN(Lat_N), 4) 6 | FROM Station 7 | WHERE Lat_N > 38.7780; 8 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/014. Weather Observation Station 17.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-17/problem 2 | -- # Score: 15 3 | 4 | 5 | SELECT * 6 | FROM ( 7 | SELECT ROUND(Long_W, 4) 8 | FROM Station 9 | WHERE Lat_N > 38.7780 10 | ORDER BY Lat_N ASC) 11 | WHERE ROWNUM = 1; 12 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/015. Weather Observation Station 18.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-18/problem 2 | -- # Score: 25 3 | 4 | 5 | SELECT ROUND(MAX(Lat_N) - MIN(Lat_N) + MAX(Long_W) - MIN(Long_W), 4) 6 | FROM Station; 7 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/016. Weather Observation Station 19.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-19/problem 2 | -- # Score: 30 3 | 4 | 5 | SELECT 6 | ROUND( 7 | SQRT( 8 | POWER((MAX(Lat_N) - MIN(Lat_N)), 2) + 9 | POWER((MAX(Long_W) - MIN(Long_W)), 2) 10 | ) 11 | , 4) 12 | FROM Station; 13 | -------------------------------------------------------------------------------- /SQL/03. Aggregation/017. Weather Observation Station 20.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/weather-observation-station-20/problem 2 | -- # Score: 40 3 | 4 | 5 | SELECT ROUND(MEDIAN(Lat_N), 4) 6 | FROM Station; 7 | -------------------------------------------------------------------------------- /SQL/04. Basic Join/001. Asian Population.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/asian-population/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT SUM(CITY.POPULATION) 6 | FROM CITY 7 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE 8 | WHERE COUNTRY.CONTINENT = 'Asia'; 9 | -------------------------------------------------------------------------------- /SQL/04. Basic Join/002. African Cities.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/african-cities/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT CITY.NAME 6 | FROM CITY 7 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE 8 | WHERE CONTINENT = 'Africa'; 9 | -------------------------------------------------------------------------------- /SQL/04. Basic Join/003. Average Population of Each Continent.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/average-population-of-each-continent/problem 2 | -- # Score: 10 3 | 4 | 5 | SELECT COUNTRY.CONTINENT, FLOOR(AVG(CITY.POPULATION)) 6 | FROM CITY 7 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE 8 | GROUP BY COUNTRY.CONTINENT; 9 | -------------------------------------------------------------------------------- /SQL/04. Basic Join/004. The Report.sql: -------------------------------------------------------------------------------- 1 | -- # Problem: https://www.hackerrank.com/challenges/the-report/problem 2 | -- # Score: 20 3 | 4 | 5 | SELECT 6 | CASE WHEN G.Grade > 7 THEN S.Name ELSE 'NULL' END AS NameOrNull 7 | , G.Grade 8 | , S.Marks 9 | FROM Students S 10 | JOIN Grades G ON S.Marks BETWEEN G.Min_Mark AND G.Max_Mark 11 | ORDER BY G.Grade DESC, NameOrNull ASC, S.Marks ASC; 12 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/001. Day 0 - Mean, Median, and Mode.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-basic-statistics/problem 2 | # Score: 30 3 | 4 | 5 | import numpy as np 6 | from scipy import stats 7 | 8 | 9 | n = int(input()) 10 | arr = list(map(int, input().split())) 11 | print(np.mean(arr)) 12 | print(np.median(arr)) 13 | print(stats.mode(arr)[0][0]) 14 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/002. Day 0 - Weighted Mean.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-weighted-mean/problem 2 | # Score: 30 3 | 4 | 5 | n = int(input()) 6 | arr = list(map(int, input().split())) 7 | weights = list(map(int, input().split())) 8 | print(round(sum([arr[x]*weights[x] for x in range(len(arr))]) / sum(weights), 1)) 9 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/003. Day 1 - Quartiles.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-quartiles/problem 2 | # Score: 30 3 | 4 | 5 | def find_median(arr): 6 | if len(arr) % 2 == 1: 7 | return arr[len(arr) // 2] 8 | else: 9 | return (arr[len(arr) // 2] + arr[len(arr) // 2 - 1]) // 2 10 | 11 | 12 | n = input() 13 | arr = sorted(list(map(int, input().split()))) 14 | print(find_median(arr[:len(arr)//2])) 15 | print(find_median(arr)) 16 | print(find_median(arr[len(arr) // 2 + len(arr) % 2:])) 17 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/004. Day 1 - Interquartile Range.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-interquartile-range/problem 2 | # Score: 30 3 | 4 | 5 | def find_median(arr): 6 | if len(arr) % 2 == 1: 7 | return arr[len(arr) // 2] 8 | else: 9 | return (arr[len(arr) // 2] + arr[len(arr) // 2 - 1]) / 2 10 | 11 | 12 | # create array 13 | n = int(input()) 14 | values = list(map(int, input().split())) 15 | freq = list(map(int, input().split())) 16 | arr = [] 17 | for i in range(n): 18 | arr += [values[i]] * freq[i] 19 | arr = sorted(arr) 20 | 21 | # find iqr 22 | iqr = float(find_median(arr[len(arr) // 2 + len(arr) % 2:]) - find_median(arr[:len(arr)//2])) 23 | print(iqr) 24 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/005. Day 1 - Standard Deviation.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-standard-deviation/problem 2 | # Score: 30 3 | 4 | 5 | n = int(input()) 6 | arr = list(map(int, input().split())) 7 | avg = sum(arr) / len(arr) 8 | std = (sum([(arr[x] - avg)**2 for x in range(n)])/n)**(1/2) 9 | print(std) 10 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/006. Day 4 - Binomial Distribution I.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-binomial-distribution-1/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | p = 1.09/(1+1.09) 9 | ans = 0 10 | for i in range(3): 11 | ans += math.factorial(6) / math.factorial(i) / math.factorial(6-i) * p**i * (1-p)**(6-i) 12 | print(round(1-ans, 3)) 13 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/007. Day 4 - Binomial Distribution II.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-binomial-distribution-2/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | p = 0.12 9 | ans1 = 0 10 | for i in range(0, 3): 11 | ans1 += math.factorial(10)/math.factorial(i)/math.factorial(10-i) * p**i * (1-p)**(10-i) 12 | if i == 1: 13 | ans2 = 1 - ans1 14 | 15 | print(round(ans1, 3)) 16 | print(round(ans2, 3)) 17 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/008. Day 4 - Geometric Distribution I.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-geometric-distribution-1/problem 2 | # Score: 30 3 | 4 | 5 | p = 1 / 3 6 | print(round((1-p)**4*p, 3)) 7 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/009. Day 4 - Geometric Distribution II.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-geometric-distribution-2/problem 2 | # Score: 30 3 | 4 | 5 | ans = 0 6 | p = 1 / 3 7 | for i in range(1, 6): 8 | ans += (1-p)**(i-1) * p 9 | print(round(ans, 3)) -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/010. Day 5 - Poisson Distribution I.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-poisson-distribution-1/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | l = 2.5 7 | k = 5 8 | print(round(l**k*math.exp(-l)/math.factorial(k), 3)) 9 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/011. Day 5 - Poisson Distribution II.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-poisson-distribution-2/problem 2 | # Score: 30 3 | 4 | 5 | print(round(160+40*(0.88**2 + 0.88), 3)) 6 | print(round(128+40*(1.55**2 + 1.55), 3)) 7 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/012. Day 5 - Normal Distribution I.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-normal-distribution-1/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | def cdf(x, mean, std): 9 | return 1/2*(1+math.erf((x-mean) / std / 2**(1/2))) 10 | 11 | 12 | mean = 20 13 | std = 2 14 | 15 | # Less than 19.5 hours 16 | print(round(cdf(19.5, mean, std), 3)) 17 | # Between 20 and 22 hours? 18 | print(round(cdf(22, mean, std) - cdf(20, mean, std), 3)) 19 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/013. Day 5 - Normal Distribution II.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-normal-distribution-2/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | def cdf(x, mean, std): 9 | return 1/2*(1+math.erf((x-mean) / std / 2**(1/2))) 10 | 11 | 12 | mean = 70 13 | std = 10 14 | 15 | # Scored higher than 80 16 | print(round((1 - cdf(80, mean, std))*100, 2)) 17 | # Passed the test (i.e., have a grade >= 60)? 18 | print(round((1 - cdf(60, mean, std))*100, 2)) 19 | # Failed the test (i.e., have a grade < 60)? 20 | print(round(cdf(60, mean, std)*100, 2)) 21 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/014. Day 6 - The Central Limit Theorem I.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-1/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | def cdf(x, mean, std): 9 | return 1/2*(1+math.erf((x-mean) / std / 2**(1/2))) 10 | 11 | 12 | # inputs 13 | mean = 205 14 | std = 15 15 | n = 49 16 | target = 9800 17 | 18 | # characteristics of sum 19 | mean_s = n * mean 20 | std_s = std * n**(1/2) 21 | 22 | # Find the probability that sum <= 9800 23 | print(round(cdf(target, mean_s, std_s), 4)) 24 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/015. Day 6 - The Central Limit Theorem II.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-2/problem 2 | # Score: 30 3 | 4 | 5 | import math 6 | 7 | 8 | def cdf(x, mean, std): 9 | return 1/2*(1+math.erf((x-mean) / std / 2**(1/2))) 10 | 11 | # inputs 12 | mean = 2.4 13 | std = 2 14 | n = 100 15 | target = 250 16 | 17 | # characteristics of sum 18 | mean_s = n * mean 19 | std_s = std * n**(1/2) 20 | 21 | # Find the probability that sum <= 250 22 | print(round(cdf(target, mean_s, std_s), 4)) 23 | -------------------------------------------------------------------------------- /Tutorials/01. 10 Days of Statistics/016. Day 6 - The Central Limit Theorem III.py: -------------------------------------------------------------------------------- 1 | # Problem: https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-3/problem 2 | # Score: 30 3 | 4 | 5 | # inputs 6 | mean = 500 7 | std = 80 8 | n = 100 9 | z = 1.96 10 | 11 | # characteristics of sample 12 | mean = mean 13 | std = std / n**(1/2) 14 | 15 | # Find the 95% interval 16 | print(round(mean - std * z, 2)) 17 | print(round(mean + std * z, 2)) 18 | --------------------------------------------------------------------------------