Skip to content

Latest commit

 

History

History
653 lines (596 loc) · 64.1 KB

README_V2.md

File metadata and controls

653 lines (596 loc) · 64.1 KB

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.

Core CS AlgorithmsPoints

General Programming

Algorithms

Implementation

Debugging

DataStructures

  • Arrays
  • Linked Lists
  • Trees
  • Balanced Trees
  • Stacks
  • Queues
  • Heap
  • Disjoint Set
  • Multiple Choice
  • Trie
  • Advanced

Math

  • Fundamentals
  • Number Theory
  • Combinatorics
  • Algebra
  • Geometry
  • Probability
  • Linear Algebra Foundations

Languages

C++

  • Introduction
  • Strings
  • Classes
  • STL
  • Inheritance
  • Other Concepts

Java

  • Introduction
  • Strings
  • BigNumber
  • Data Structures
  • Object Oriented Programming
  • Exception Handling
  • Advanced

Python

  • 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

Solutions

Basic Programming

# Title Solution Time Space Difficulty Points Note
Solve Me First Java O(1) O(1) Easy 1
Staircase Java O(n) O(n) Easy 10
Plus Minus Java O(n) O(1) Easy 10
Diagonal Difference Java O(n^2) O(1) Easy 10
A Very Big Sum Java O(n) O(1) Easy 10
Simple Array Sum Java O(n) O(1) Easy 10
Compare the Triplets Java O(1) O(1) Easy 10
Divisible Sum Pairs Java O(n^2) O(n) Easy 10
Kangaroo Java O(1) O(1) Easy 10
Drawing Book Java Easy 10
Birthday Cake Candles Java O(n) O(1) Easy 10
Bon Appetit Java Easy 10
Sock Merchant Java Easy 10
Apple and Orange Java Easy 10
Between Two Sets Java O((A^2)+B) O(1) Easy 10
Mini-Max Sum Java O(1) O(1) Easy 10
Grading Students Java O(n) O(1) Easy 10
Breaking the Records Java O(n) O(1) Easy 10
Migratory Birds Java Easy 10
Birthday Chocolate Java O(n) O(1) Easy 10
Time Conversion Java O(1) O(1) Easy 15
Library Fine Java Easy 15
Save the Prisoner! Java Easy 15
Jumping on the Clouds: Revisited Java Easy 15
Counting Valleys Java O(n) O(1) Easy 15
Viral Advertising Java Easy 15
Beautiful Days at the Movies Java Easy 15
Electronics Shop Java O(n log (n)) O(1) Easy 15 n = m+n
Cats and a Mouse Java O(1) O(1) Easy 15
The Hurdle Race Java O(n) O(1) Easy 15
Utopian Tree Java Easy 20
Service Lane Java Easy 20
Circular Array Rotation Java Easy 20
Sherlock and Squares Java Easy 20
Angry Professor Java Easy 20
Extra Long Factorials Java Medium 20
Minimum Distances Java Easy 20
Non-Divisible Subset Java Medium 20
Beautiful Triplets Java Easy 20
Jumping on the Clouds Java Easy 20
Equalize the Array Java Easy 20
Designer PDF Viewer Java Easy 20
Magic Square Forming Java Easy 20
Repeated String Java Easy 20
Bitwise AND Java Easy 20
Divisible Pairs Sum Java Easy 20
Append and Delete Java Easy 20
Picking Numbers Java O(n) O(n) Easy 20
Climbing the Leaderboard Java O(n+m) (n) Easy 20
Sequence Equation Java O(n) O(n) Easy 20
Find Digits Java Easy 25
Chocolate Feast Java Easy 25
Cut the sticks Java Easy 25
ACM ICPC Team Java Easy 25
Taum and B'day Java Easy 25
The Time in Words Java Medium 25
Flatland Space Stations Java Easy 25
Lisa's Workbook Java Easy 25
Fair Rations Java Easy 25
Manasa and Stones Java Easy 30
Cavity Map Java Easy 30
The Grid Search Java Medium 30
Happy Ladybugs Java Easy 30
Strange Counter Java Easy 30
Consecutive 1's in Binary Numbers Java Easy 30
Nested Logic Java Easy 30

Object-Oriented Programming

# 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

RegEx

# 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

Sorting

# Title Solution Time Space Difficulty Points Note
Intro to Tutorial Challenges Java O(n) O(1) Easy 30
Insertion Sort - Part 1 Java O(n) O(1) Easy 30
Insertion Sort - Part 2 Java O(n^2) O(1) Easy 30
Insertion Sort Advanced Analysis Java Advanced 50
Correctness and the Loop Invariant Java O(n^2) O(1) Easy 30
Running Time of Algorithms Java O(n^2) O(1) Easy 30
Quicksort 1 - Partition Java O(n) O(n) Easy 10
Quicksort 2 - Sorting Java O(n^2) O(n) Easy 30
Quicksort In-Place Java O(n^2) O(log(n)) Medium 35
Running Time of Quicksort Java O(n log(n)) O(log(n)) Easy 35
Counting Sort 1 Java O(n+k) O(k) Easy 30
Counting Sort 2 Java O(n+k) O(k) Easy 30
Counting Sort 3 Java O(n+k) O(k) Easy 30
The Full Counting Sort Java O(n+k) O(k) Medium 40
Marc's Cakewalk Java O(n + k) O(k) Easy 15
Minimum Absolute Difference in an Array Java O(n log(n)) O(1) Easy 15
Organizing Containers of Balls Java O(n^2) O(n^2) Medium 30
Find the Median Java O(n log(n)) O(n) Easy 35
Closest Numbers Java O(n log(n)) O(n) Easy 35
Mark and Toys Java O(n log(n)) O(n) Easy 35
Permuting Two Arrays Java O(n log (n)) O(n) Easy 40
Jim and the Orders Java O(n log (n)) O(n) Easy 40
Fraudulent Activity Notifications Java O(n^2) O(n) Medium 40
Lily's Homework Java O(n log(n)) O(n) Medium 40
Merge Sort: Counting Inversions Java Hard 45
Mr. X and His Shots Java Medium 50
Super Maximum Cost Queries Java Hard 60
GCD Matrix Java Hard 60
A Super Hero Java Hard 80
Functional Palindromes Java Advanced 80
Super Functional Strings Java Advanced 80
Sorted Subsegments Java Hard 80

Search

# 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

Greedy Algorithms

# 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

Graph Theory

# 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

Strings

# Title Solution Time Space Difficulty Points Note
Super Reduced String Java Easy 10
camelCase Java Easy 15
Two Characters Java O(n) O(1) Easy 15
Caesar Cipher Java Easy 15
Mars Exploration Java Easy 15
Weighted Uniform Strings Java Easy 20
Separate the Numbers Java Easy 20
Funny String Java Easy 25
Gemstones Java Easy 20
Alternating Characters Java Easy 20
Beautiful Binary String Java Easy 20
The Love-Letter Mystery Java O(n) O(1) Easy 20
Determining DNA Health Java Hard 50
Palindrome Index Java Easy 25
Anagram Java O(n) O(1) Easy 25
Game of Thrones - I Java O(n) O(1) Easy 30
Two Strings Java O(|a| + |b|) O(1) Easy 25
String Construction Java Easy 25
Sherlock and Valid String Java O(n) O(n) Hard 100
Richie Rich Java Medium 30
Sherlock and Anagrams Java Medium 50
Common Child Java Hard 60
Bear and Steady Gene Java Medium 50
Morgan and a String Java Expert 100
Count Strings Java Hard 80
String Function Calculation Java Advanced 80
Build a Palindrome Java Advanced 80
Build a String Java Hard 80
Gridland Provinces Java Hard 80
Ashton and String Java Advanced 100
String Similarity Java Expert 100
Super Functional Strings Java Advanced 80
Circular Palindromes Java Advanced 120
Similar Strings Java Advanced 85
Save Humanity Java Expert 100
Find Strings Java Expert 100
Palindromic Border Java Expert 100
Two Two Java Advanced 150
Two Strings Game Java Expert 100
Letter Islands Java Expert 100
Pseudo-Isomorphic Substrings Java Expert 100
How Many Substrings? Java Expert 100

Dynamic Programming

# 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

Bit Manipulation

# Title Solution Time Space Difficulty Points Note

Recursion

# 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

Constructive Algorithms

# 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

Brute-Force

# 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
Maximixing 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

Missing Lines

# Title Solution Time Space Difficulty Points Note
Lonely Integer - Fill the key-line Java Easy 20
Make It Anagram Java Easy 20

Data Structures

Arrays

# Title Solution Time Space Difficulty Points Note

Stacks

# Title Solution Time Space Difficulty Points Note

Trees

# Title Solution Time Space Difficulty Points Note

Linked Lists

# Title Solution Time Space Difficulty Points Note
Compare two linked lists C++ O(n) O(1) Easy 5

Graphs

# Title Solution Time Space Difficulty Points Note

Tries

# Title Solution Time Space Difficulty Points Note

Queues

# Title Solution Time Space Difficulty Points Note

Suffix Array

# Title Solution Time Space Difficulty Points Note

Heaps

# Title Solution Time Space Difficulty Points Note

Disjoint Set

# Title Solution Time Space Difficulty Points Note

Math

Number Theory

# Title Solution Time Space Difficulty Points Note

Game Theory

# Title Solution Time Space Difficulty Points Note

Geometry

# Title Solution Time Space Difficulty Points Note

Algebra

# Title Solution Time Space Difficulty Points Note

Fundamentals

# Title Solution Time Space Difficulty Points Note

Combinatorics

# Title Solution Time Space Difficulty Points Note

Probability

# 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 | ||