Solutions to problems on HackerRank.
HackerRank's new problem format!
If you are interested in helping or have a solution in a different language feel free to make a pull request.
- Sorting
- Search
- Greedy Algorithms
- Graph Theory
- Strings
- Dynamic Programming
- Bit Manipulation
- Recursion
- Arrays
- Linked Lists
- Trees
- Balanced Trees
- Stacks
- Queues
- Heap
- Disjoint Set
- Multiple Choice
- Trie
- Advanced
- Fundamentals
- Number Theory
- Combinatorics
- Algebra
- Geometry
- Probability
- Linear Algebra Foundations
- Introduction
- Strings
- Classes
- STL
- Inheritance
- Other Concepts
- Introduction
- Strings
- BigNumber
- Data Structures
- Object Oriented Programming
- Exception Handling
- Advanced
- Introduction
- Classes
- Basic Data Types
- Strings
- Python Functionals
- Regex and Parsing
- XML
- Closures and Decorators
- Sets
- Math
- Itertools
- Collections
- Date and Time
- Errors and Exceptions
- Numpy
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Class vs. Instance | Java | Easy | 30 | ||||
Inheritance | Java | O(n) | O(1) | Easy | 30 | ||
Abstract Classes | Java | Easy | 30 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
UK and US: Part 2 | Java | Easy | 10 | ||||
Alien Username | Java | Easy | 10 | ||||
Detect HTML Tags | Java | Easy | 10 | ||||
Detect HTML links | Java | Easy | 10 | ||||
Find A Sub-Word | Java | Easy | 10 | ||||
IP Address Validation | Java | Easy | 10 | ||||
Find HackerRank | Java | Easy | 15 | ||||
The British and American Style of Spelling | Java | Easy | 15 | ||||
Split the Phone Numbers | Java | Easy | 15 | ||||
Valid PAN format | Java | Easy | 15 | ||||
Saying Hi | Java | Easy | 15 | ||||
HackerRank Tweets | Java | Easy | 15 | ||||
HackerRank Language | Java | Easy | 15 | ||||
Utopian Identification Number | Java | Easy | 15 | ||||
Find a Word | Java | Medium | 15 | ||||
Build a Stack Exchange Scraper | Java | Easy | 15 | ||||
Detect the Domain Name | Java | Medium | 15 | ||||
Detect the Email Addresses | Java | Medium | 15 | ||||
Detect HTML Attributes | Java | Easy | 20 | ||||
HackerRank in a String! | Java | O(n) | O(1) | Easy | 20 | ||
Building a Smart IDE: Programming Language Detection | Java | Medium | 30 | ||||
Count Strings | Java | Hard | 80 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Hackerland Radio Transmitters | JS | O(n log(n)) | O(1) | Easy | 15 | ||
Lonely Integer | Java | O(n) | O(1) | Easy | 20 | ||
Bit Manipulation: Lonely Integer | Java | O(n) | O(1) | Easy | 20 | ||
Gridland Metro | Java | Medium | 25 | ||||
Ice Cream Parlor | Java | O(n) | O(n) | Easy | 30 | ||
Greedy Florist | Java | Medium | 35 | ||||
Find the Median | Java | O(n log(n)) | O(n) | Easy | 35 | ||
Closest Numbers | Java | O(n log(n)) | O(n) | Easy | 35 | ||
Binary Search: Ice Cream Parlor | Java | O(n) | O(n) | Easy | 35 | ||
Minimum Loss | Java | O(n log(n)) | O(n) | Medium | 35 | ||
KnightL on a Chessboard | Java | Medium | 35 | ||||
Sherlock and Array | Java C++ | O(n) | O(n) | Easy | 40 | ||
Short Palindrome | Java | Medium | 40 | ||||
Missing Numbers | Java | Easy | 45 | ||||
Making Candies | Java | Hard | 45 | ||||
DFS: Connected Cell in a Grid | Java | hard | 45 | ||||
Pairs | Java | Medium | 50 | ||||
Count Luck | Java | Medium | 50 | ||||
Cut the Tree | Java | Medium | 50 | ||||
Connected Cells in a grid | Java | Medium | 50 | ||||
Gena Playing Hanoi | Java | Medium | 50 | ||||
Beautiful Quadruples | Java | Medium | 50 | ||||
Coin on the Table | Java | Medium | 65 | ||||
Interval Selection | Java | Medium | 65 | ||||
Bike Racers | Java | Hard | 65 | ||||
Maximum Subarray Sum | Java | Hard | 65 | ||||
Task Scheduling | Java | Advanced | 70 | ||||
Queens on Board | Java | Hard | 70 | ||||
Median Updates | Java | Hard | 70 | ||||
Similar Pair | Java | Advanced | 70 | ||||
Absolute Element Sums | Java | Hard | 70 | ||||
Maximizing Mission Points | Java | Hard | 70 | ||||
Arithmetic Progressions | Java | Advanced | 80 | ||||
Billboards | Java | Advanced | 80 | ||||
Requirement | Java | Advanced | 80 | ||||
King Richard's Knights | Java | Hard | 80 | ||||
Sorted Subsegments | Java | Hard | 80 | ||||
Distant Pairs | Java | Expert | 80 | ||||
Triplets | Java | Medium | 20 | ||||
Spies, Revised | Java | Expert | 100 | ||||
TBS Problem | Java | Expert | 100 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Two Characters | Java | O(n) | O(1) | Easy | 15 | ||
Marc's Cakewalk | Java | O(n + k) | O(k) | Easy | 15 | ||
Grid Challenge | Java | O(n*(n log (n))) | O(n^2) | Easy | 20 | ||
Luck Balance | Java | O(n log(n)) | O(1) | Easy | 20 | ||
Maximum Perimeter Triangle | Java | O(n log (n)) | O(n) | Easy | 20 | ||
Equal Stacks | Java | O(n) | O(n) | Easy | 25 | ||
Sherlock and The Beast | Java | O(n) | O(n) | Easy | 30 | ||
Priyanka and Toys | Java | O(n log(n)) | O(n) | Easy | 30 | ||
Largest Permutation | Java | Easy | 30 | ||||
Beautiful Pairs | Java | Easy | 30 | ||||
Yet Another Minimax Problem | Java | Medium | 20 | ||||
Flipping the Matrix | Java | O(n^2) | O(n^2) | Medium | 30 | ||
Roads and Libraries | Java | Medium | 30 | ||||
Greedy Florist | Java | Medium | 35 | ||||
Mark and Toys | Java | O(n log(n)) | O(n) | Easy | 35 | ||
Max Min | Java | Medium | 35 | ||||
Permuting Two Arrays | Java | Easy | 40 | ||||
Jim and the Orders | Java | Easy | 40 | ||||
Goodland Electricity | Java | Medium | 40 | ||||
Fun Game | Java | Medium | 40 | ||||
Reverse Shuffle Merge | Java | Advanced | 50 | ||||
Cutting Boards | Java | Hard | 60 | ||||
Algorithmic Crush | Java | Hard | 60 | ||||
Prim's (MST): Special Subtree | Java | Medium | 60 | ||||
Accessory Collection | Java | Hard | 60 | ||||
Chief Hopper | Java | O(n) | O(n) | Hard | 65 | ||
Sherlock and MiniMax | Java | Hard | 70 | ||||
Team Formation | Java | Advanced | 70 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Roads and Libraries | Java | Medium | 30 | ||||
Synchronous Shopping | Java | Medium | 40 | ||||
Crab Graphs | Java | Medium | 50 | ||||
Even Tree | Java | Medium | 50 | ||||
Snakes and Ladders: THe Quickest Way Up | Java | Medium | 50 | ||||
Subset Component | Java | Hard | 50 | ||||
Journey to the Moon | Java Python 3 | O(n + i) | O(n) | Medium | 50 | ||
Kruskal (MST): Really Special Subtree | Java | Hard | 50 | ||||
Minimum Penalty Path | Java | Medium | 50 | ||||
Demanding Money | Java | Hard | 50 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Equal | Java | Medium | 30 | ||||
Cut Tree | Java | Medium | 40 | ||||
Mr K marsh | Java | Medium | 40 | ||||
Sam and sub-strings | Java | Medium | 40 | ||||
Summing Pieces | Java | Medium | 40 | ||||
Short Palindrome | Java | Medium | 40 | ||||
Abbreviation | Java | Medium | 40 | ||||
Fair Cut | Java | Medium | 40 | ||||
Fibonacci Modified | Java | Medium | 45 | ||||
Lego Blocks | Java | Medium | 50 | ||||
Candies | Java | Medium | 50 | ||||
Stock Maximize | Java | Medium | 50 | ||||
Angry Childtren 2 | Java | Hard | 50 | ||||
The Maximum Subarray | Java | Medium | 50 | ||||
Sherlock and Cost | Java | Medium | 50 | ||||
Xor and Sum | Java | Medium | 50 | ||||
Counting Special Sub-Cubes | Java | Medium | 50 | ||||
Two Robots | Java | Medium | 50 | ||||
Kingdom Division | Java | Medium | 50 | ||||
Prime XOR | Java | Medium | 50 | ||||
HackerRank City | Java | Medium | 50 | ||||
Nikita and the Game | Java | Medium | 50 | ||||
Prime Digit Sums | Java | Medium | 50 | ||||
Mandragora Forest | Java | Medium | 50 | ||||
LCS Returns | Java | Medium | 50 | ||||
Grid Walking | Java | Medium | 55 | ||||
Bricks Game | Java | Medium | 55 | ||||
The Longest Common Subsequence | Java | Medium | 55 | ||||
Substring Diff | Java | Medium | 60 | ||||
Brick Tiling | Java | Hard | 60 | ||||
Alien Languages | Java | Hard | 60 | ||||
The Longest Increasing Subsequence | Java | Advanced | 60 | ||||
The Coin Change Problem | Java | Hard | 60 | ||||
Knapsack | Java | Medium | 60 | ||||
Sherlock's Array Merging Algorithm | Java | Hard | 60 | ||||
New Year Game | Java | Medium | 60 | ||||
Shashank and the Palindromic Strings | Java | Advanced | 60 | ||||
Decibinary Numbers | Java | Hard | 60 | ||||
Choosing White Balls | Java | Hard | 60 | ||||
DP: Coin Change | Java | Hard | 60 | ||||
Clues on a Binary Path | Java | Hard | 60 | ||||
GCD Matrix | Java | Hard | 60 | ||||
Coin on the Table | Java | Medium | 65 | ||||
Interval Selection | Java | Medium | 65 | ||||
Red John is Back | Java | Medium | 65 | ||||
Play with words | Java | Medium | 65 | ||||
Queens on Board | Java | Hard | 70 | ||||
String Reduction | Java | Hard | 70 | ||||
Far Vertices | Java | Hard | 70 | ||||
The Indian Job | Java | Medium | 70 | ||||
Hexagonal Grid | Java | Hard | 70 | ||||
Longest Palindromic Subsequence | Java | Hard | 70 | ||||
Turn Off the Lights | Java | Hard | 70 | ||||
Tara's Beautiful Permutations | Java | Hard | 70 | ||||
Two Subarrays | Java | Expert | 70 | ||||
Mining | Java | Advanced | 75 | ||||
The Longest Common Subsequence (LCS) | Java | Hard | 75 | ||||
Points in a Plane | Java | Advanced | 80 | ||||
Fairy Chess | Java | Advanced | 80 | ||||
Billboards | Java | Advanced | 80 | ||||
Requirement | Java | Advanced | 80 | ||||
A Super Hero | Java | Hard | 80 | ||||
Covering the stains | Java | Hard | 80 | ||||
Superman Celebrates Diwali | Java | Hard | 80 | ||||
Wet Shark and Two Subsequences | Java | Medium | 80 | ||||
Zurikela's Graph | Java | Hard | 80 | ||||
New Year Present | Java | Hard | 80 | ||||
Suffix Rotation | Java | Expert | 80 | ||||
Black and White Tree | Java | Hard | 80 | ||||
Beautiful Strings | Java | Hard | 80 | ||||
Longest Mod Path | Java | Hard | 80 | ||||
Super Functional Strings | Java | Advanced | 80 | ||||
Kitty's Calculations on a Tree | Java | Advanced | 80 | ||||
Liars | Java | Advanced | 85 | ||||
Dorsey Thief | Java | Advanced | 85 | ||||
Swap Permutation | Java | Medium | 85 | ||||
Candles Counting | Java | Medium | 85 | ||||
Square Subsequences | Java | Hard | 90 | ||||
Hyper Strings | Java | Advanced | 90 | ||||
Unique Divide And Conquer | Java | Advanced | 90 | ||||
Super Kth LIS | Java | Advanced | 90 | ||||
Counting Road Networks | Java | Expert | 90 | ||||
Lucky Numbers | Java | Expert | 100 | ||||
Count Scorecards | Java | Expert | 100 | ||||
Unfair Game | Java | Advanced | 100 | ||||
Oil Well | Java | Hard | 100 | ||||
Modify The Sequence | Java | Advanced | 100 | ||||
Divisible Numbers | Java | Expert | 100 | ||||
Ones and Twos | Java | Hard | 100 | ||||
Extremum Permutations | Java | Medium | 100 | ||||
Tree Pruning | Java | Advanced | 100 | ||||
P-sequences | Java | Hard | 100 | ||||
Best spot | Java | Advanced | 100 | ||||
Find the Seed | Java | Advanced | 100 | ||||
The Blacklist | Java | Advanced | 100 | ||||
Police Operation | Java | Hard | 100 | ||||
Road Maintenance | Java | Hard | 100 | ||||
King and Four Sons | Java | Expert | 100 | ||||
Counting the Ways | Java | Expert | 100 | ||||
Hard Disk Drives | Java | Expert | 100 | ||||
Travel around the world | Java | Medium | 120 | ||||
Robot | Java | Advanced | 120 | ||||
Vim War | Java | Advanced | 120 | ||||
Dortmund Dilemma | Java | Advanced | 150 | ||||
Separate the chocolate | Java | Expert | 250 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
The Power Sum | Java | Easy | 20 | ||||
Crossword Puzzle | Java | Medium | 30 | ||||
Recursive Digit Sum | Java | Medium | 30 | ||||
Simplified Chess Engine | Java | Medium | 40 | ||||
Password Cracker | Java | Medium | 40 | ||||
Artithmetic Expressions | Java | Hard | 40 | ||||
K Factorization | Java | Hard | 50 | ||||
Bowling Pins | Java | Advanced | 60 | ||||
Simplified Chess Engine II | Java | Hard | 60 | ||||
Repetitive K-Sums | Java | Advanced | 150 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Lena Sort | Java | Medium | 30 | ||||
Flipping the Matrix | Java | O(n^2) | O(n^2) | Medium | 30 | ||
Gaming Array | Java | Medium | 35 | ||||
New Year Chaos | Java | Medium | 40 | ||||
Bonetrousle | Java | Medium | 50 | ||||
Yet Another KMP Problem | Java | Hard | 60 | ||||
Beautiful 3 Set | Java | Hard | 60 | ||||
Inverse RMQ | Java | Hard | 60 | ||||
Two Subarrays | Java | Expert | 70 | ||||
Lovely Triplets | Java | Advanced | 80 | ||||
Array Construction | Java | Advanced | 80 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Pangrams | Java | Easy | 20 | ||||
Climbing the Leaderboard | Java | O(n+m) | (n) | Easy | 20 | ||
Strings: Making Anagrams | Java | O(|a|+|b|) | O(1) | Easy | 30 | ||
Enryption | Java | Medium | 30 | ||||
Making Anagrams | Java | Easy | 30 | ||||
Modified Kaprekar Numbers | Java | Easy | 30 | ||||
Queen's Attack II | Java | O(k) | O(1) | Medium | 30 | ||
Organizing Containers of Balls | Java | O(n^2) | O(n^2) | Medium | 30 | ||
Bigger is Greater | Java | Medium | 35 | ||||
Ema's Supercomputer | Java | Medium | 40 | ||||
Absolute Permuation | Java | Medium | 40 | ||||
Larry's Array | Java | Medium | 40 | ||||
The Bomberman Game | Java | O(n*m) | O(n*m) | Medium | 40 | ||
Almost Sorted | Java | Medium | 50 | ||||
Beautiful Quadruples | Java | Medium | 50 | ||||
HackerRank City | Java | Medium | 50 | ||||
Maximizing the Function | Java | Hard | 70 | ||||
Matrix Layer Rotation | Java | Hard | 80 | ||||
Gridland Provinces | Java | Hard | 80 | ||||
Fighting Pits | Java | Hard | 80 | ||||
Find the permutation | Java | Expert | 150 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Lonely Integer - Fill the key-line | Java | Easy | 20 | ||||
Make It Anagram | Java | Easy | 20 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|---|---|---|---|---|---|---|
Compare two linked lists | C++ | O(n) | O(1) | Easy | 5 |
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
# | Title | Solution | Time | Space | Difficulty | Points | Note |
---|
| | Walking the Approximate Longest Path| Java | | | Hard | 70 | || | | Sam's Puzzle (Approximate)| Java | | | Advanced | 85 | || | | Java Substring| Java | O(1) | O(1) | Easy | 5 | ||