Solutions to problems on HackerRank.
Check out HackerRank's new format here
If you are interested in helping or have a solution in a different language feel free to make a pull request.
- Warmup
- Implementation
- Strings
- Sorting
- Search
- Graph Theory
- Greedy
- Dynamic Programming
- Constructive Algorithms
- Bit Manipulation
- Recursion
- Game Theory
- NP Complete
- Fundamentals
- Number Theory
- Combinatorics
- Algebra
- Geometry
- Probability
- Linear Algebra Foundations
- Introduction
- Strings
- BigNumber
- Data Structures
- Object Oriented Programming
- Exception Handling
- Advanced
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Solve Me First | O(1) | O(1) | Easy | 1 | |||
Simple Array Sum | O(n) | O(1) | Easy | 10 | |||
Compare the Triplets | O(1) | O(1) | Easy | 10 | |||
A Very Big Sum | O(n) | O(1) | Easy | 10 | |||
Diagonal Difference | O(n) | O(1) | Easy | 10 | |||
Plus Minus | O(n) | O(1) | Easy | 10 | |||
Staircase | O(n) | O(n) | Easy | 10 | |||
Mini-Max Sum | O(1) | O(1) | Easy | 10 | |||
Time Conversion | O(1) | O(1) | Easy | 15 | |||
Birthday Cake Candles | O(n) | O(1) | Easy | 10 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Intro to Tutorial Challenges | O(n) | O(1) | Easy | 30 | |||
Insertion Sort - Part 1 | O(n) | O(1) | Easy | 30 | |||
Insertion Sort - Part 2 | O(n^2) | O(1) | Easy | 30 | |||
Correctness and the Loop Invariant | O(n^2) | O(1) | Easy | 30 | |||
Running Time of Algorithms | O(n^2) | O(1) | Easy | 30 | |||
Quicksort 1 - Partition | O(n) | O(n) | Easy | 10 | |||
Quicksort 2 - Sorting | O(n^2) | O(n) | Easy | 30 | |||
Quicksort In-Place | O(n^2) | O(log(n)) | Medium | 35 | |||
Running Time of Quicksort | O(n log(n)) | O(log(n)) | Easy | 35 | |||
Counting Sort 1 | O(n+k) | O(k) | Easy | 30 | value of k in this problem is 100 | ||
Counting Sort 2 | O(n+k) | O(n+k) | Easy | 30 | Value of k is 100 in this problem. | ||
Counting Sort 3 | O(n+k) | O(k) | Easy | 30 | |||
The Full Counting Sort | O(n+k) | O(n+k) | Medium | 40 | |||
Closest Numbers | O(n log(n)) | O(n) | Easy | 35 | |||
Find the Median | O(n log(n)) | O(n) | Easy | 35 | |||
Insertion Sort Advanced Analysis |
| Advanced | 50 | ||||
Fraudulent Activity Notifications | O(n^2) | O(n) | Medium | 40 | |||
Lily's Homework | O(n log(n)) | O(n) | Medium | 40 | |||
Big Sorting | O(n log(n)) | O(n) | Easy | 20 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Hackerland Radio Transmitters | O(n log(n)) | O(n) | Medium | 25 | |||
Ice Cream Parlor | O(n) | O(n) | Easy | 30 | |||
Binary Search: Ice Cream Parlor | O(n) | O(n) | Easy | 35 | |||
Gridland Metro |
| O(k) | O(k) | Medium | 25 | k = number of tracks | |
Missing Numbers | O(n) | O(n) | Easy | 45 | |||
Minimum Loss | O(n log(n)) | O(n) | Medium | 35 | |||
KnightL on a Chessboard |
| Medium | 35 | ||||
Pairs | O(n log(n)) | O(n) | Medium | 50 | |||
Sherlock and Array | O(n) | O(n) | Easy | 40 | |||
Maximum Subarray Sum |
| Hard | 65 | ||||
Connected Cells in a grid |
| Medium | 50 | ||||
Short Palindrome |
| Medium | 40 | ||||
Maximizing Mission Points |
| Hard | 70 | ||||
Count Luck |
| Medium | 50 | ||||
Cut the Tree |
| Medium | 50 | ||||
Making Candies |
| Hard | 45 | ||||
Gena Playing Hanoi |
| Medium | 50 | ||||
Beautiful Quadruples |
| Medium | 50 | ||||
Bike Racers |
| Hard | 65 | ||||
Task Scheduling |
| Advanced | 70 | ||||
Similar Pair |
| Advanced | 70 | ||||
Absolute Element Sums |
| Hard | 70 | ||||
Sorted Subsegments |
| Hard | 80 | ||||
Distant Pairs |
| Expert | 80 | ||||
King Richard's Knights |
| Hard | 80 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Lena Sort |
| Medium | 30 | ||||
Flipping the Matrix | O(n^2) | O(n^2) | Medium | 30 | |||
Gaming Array |
| Medium | 35 | ||||
New Year Chaos |
| Medium | 40 | ||||
Bonetrousle |
| Medium | 50 | ||||
Yet Another KMP Problem |
| Hard | 60 | ||||
Beautiful 3 Set |
| Hard | 60 | ||||
Inverse RMQ |
| Hard | 60 | ||||
Two Subarrays |
| Expert | 70 | ||||
Lovely Triplets |
| Advanced | 80 | ||||
Array Construction |
| Advanced | 80 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Lonely Integer | O(n) | O(1) | Easy | 20 | |||
Maximizing XOR |
| Easy | 30 | ||||
Counter game |
| Medium | 30 | ||||
Xor-sequence |
| Medium | 40 | ||||
Sum vs XOR | O(n log(n)) | O(1) | Easy | 20 | |||
The Great XOR |
| Medium | 25 | ||||
Flipping bits |
| Easy | 40 | ||||
Yet Another Minimax Problem |
| Medium | 30 | ||||
Sansa and XOR |
| Medium | 30 | ||||
AND Product |
| Medium | 40 | ||||
Xoring Ninja |
| Hard | 55 | ||||
Cipher |
| Medium | 50 | ||||
XOR Matrix |
| Hard | 50 | ||||
What's Next? |
| Medium | 50 | ||||
String Transmission |
| Hard | 60 | ||||
A or B |
| Medium | 50 | ||||
Manipulative Numbers |
| Hard | 55 | ||||
Stone game |
| Hard | 70 | ||||
2's complement |
| Advanced | 70 | ||||
Changing Bits |
| Advanced | 70 | ||||
XOR key |
| Advanced | 80 | ||||
Maximizing the Function |
| Hard | 70 | ||||
XOR Subsequences |
| Advanced | 80 | ||||
Iterate It |
| Expert | 90 | ||||
Hamming Distance |
| Expert | 150 | ||||
Mixing proteins |
| Hard | 80 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
The Power Sum |
| Easy | 20 | ||||
Crossword Puzzle |
| Medium | 30 | ||||
Recursive Digit Sum |
| Medium | 30 | ||||
Simplified Chess Engine |
| Medium | 40 | ||||
Password er |
| Medium | 40 | ||||
Artithmetic Expressions |
| Hard | 40 | ||||
K Factorization |
| Hard | 50 | ||||
Bowling Pins |
| Advanced | 60 | ||||
Simplified Chess Engine II |
| Hard | 60 | ||||
Repetitive K-Sums |
| Advanced | 150 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Game of Stones | O(n) | O(1) | Easy | 15 | |||
Tower Breakers |
| Easy | 15 | ||||
A Chessboard Game |
| Easy | 15 | ||||
Introduction to Nim Game |
| Easy | 15 | ||||
Misère Nim |
| Easy | 20 | ||||
Nimble Game |
| Easy | 20 | ||||
Alice and Bob's Silly Game |
| Medium | 30 | ||||
Poker Nim |
| Easy | 20 | ||||
Tower Breakers, Revisited! |
| Medium | 25 | ||||
Tower Breakers, Again! |
| Medium | 30 | ||||
Zero-Move Nim |
| Medium | 50 | ||||
Chessboard Game, Again! |
| Medium | 30 | ||||
Digits Square Board |
| Medium | 35 | ||||
Fun Game |
| Medium | 40 | ||||
Stone Division |
| Hard | 50 | ||||
Chocolate in Box |
| Medium | 70 | ||||
Kitty and Katty |
| Medium | 80 | ||||
Powers Game |
| Medium | 50 | ||||
Deforestation |
| Medium | 50 | ||||
Bob and Ben |
| Medium | 50 | ||||
Tower Breakers - The Final Battle |
| Medium | 50 | ||||
Simple Game |
| Hard | 60 | ||||
Permutation game |
| Medium | 70 | ||||
Move the Coins |
| Hard | 60 | ||||
Play on benders |
| Medium | 70 | ||||
New Year Game |
| Medium | 60 | ||||
Stone Piles |
| Hard | 80 | ||||
Chocolate Game |
| Hard | 90 | ||||
Manasa and Prime game |
| Hard | 90 | ||||
Vertical Rooks |
| Medium | 90 | ||||
A stones game |
| Medium | 90 | ||||
Tastes Like Winning |
| Expert | 100 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Walking the Approximate Longest Path |
| Hard | 70 | ||||
Sam's Puzzle (Approximate) |
| Advanced | 85 | ||||
Spies, Revised |
| Expert | 100 | ||||
TBS Problem |
| Expert | 100 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Class vs. Instance | N/A | N/A | Easy | 30 | |||
Inheritance | O(n) | O(1) | Easy | 30 | |||
Abstract Classes | N/A | N/A | Easy | 30 | |||
Complex Numbers | O(1) | O(1) | Easy | 30 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Arrays - DS | O(n) | O(n) | Easy | 10 | |||
2D Array - DS | O(1) | O(1) | Easy | 15 | |||
Sparse Arrays | O(n + q) | O(n + q) | Medium | 25 | n = number of input strings, q = number of queries | ||
Dynamic Array | O(q) | O(n) | Easy | 15 | q = Number of queries |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Print the Elements of a Linked List | O(n) | O(1) | Easy | 5 | |||
Reverse a Linked List | O(n) | O(1) | Easy | 5 | |||
Compare Two Linked Lists | O(n) | O(1) | Easy | 5 | |||
Delete a node | O(n) | O(1) | Easy | 5 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Tree: Preorder Traversal | O(n) | O(n) | Easy | 10 | |||
Swap Nodes [Algo] | O(n) | O(n) | Medium | 40 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Self Balancing Tree | O(log(n)) | O(n) | Medium | 50 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Maximum Element | Push-O(1), Delete - O(n), Print - O(1) | Push - O(1), Delete - O(1), Print - O(1) | Easy | 20 | |||
Balanced Brackets | O(n) | O(n) | Medium | 25 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Queue using Two Stacks | Enqueue - O(1), Dequeue - O(n), Print - O(n) | Enqueue - O(1), Dequeue - O(1), Print - O(1) | Medium | 30 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
QHEAP1 | Insert - O(log(n)), Delete - O(n), Print - O(1) | Insert - O(1), Delete - O(1), Print - O(1) | Easy | 25 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Spaceholder | O(1) | O(1) | Easy | 1 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Data Structures MCQ 1 | NA | NA | Hard | 5 | |||
Data Structures MCQ 2 | NA | NA | Hard | 5 | |||
Data Structures MCQ 3 | NA | NA | Hard | 5 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Contacts | Add - O(L), Find - O(L) | Add - O(L), Find - O(1) | Medium | 40 | L = Length of a contact name |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Spaceholder | O(1) | O(1) | Easy | 1 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Leonardo's Prime Factors | O(1) | O(1) | Easy | 10 |