This is a repo for HackerRank Solutions in Swift
Different folders are named after corresponding domain names or contest names.
Problem | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|
Angry Professor | O(n) | Easy | Implementation | ||
SherlockAndTheBeast | O(n) | Easy | Implementation | ||
Utopian Tree | O(n) | Easy | Implementation | ||
Find Digits | O(n) | Easy | Implementation | ||
Funny String | O(n) | Easy | String | ||
Pangrams | O(n) | O(1) | Easy | String | |
Alternating Characters | O(n) | O(1) | Easy | String | |
Game of Thrones | O(n) | O(1) | Easy | String | |
Make it anagram | O(n) | O(1) | Easy | String | |
Anagram | O(n) | O(1) | Easy | String | |
Two Strings | O(n) | O(1) | Moderate | String | Set |
SherlockAndAnagrams | O(n^3lgn) | O(n^2) | Moderate | String | Sort, Dictionary, Permutation |
Palindrome Index | O(n) | O(1) | Easy | String | |
Sherlock And Valid String | O(n) | O(1) | Difficult | String | Dictionary |
The Maximum Subarray | O(n) | O(n) | Easy | Dynamic Programming | |
The Coin Change Problem | O(MN) | O(MN) | Medium | Dynamic Programming | bottom-up table construction |
Knapsack | O(MN) | O(MN) | Moderate | Dynamic Programming | memoization in swift |
The Longest Increasing Subsequence | O(N^2) | O(N) | Advanced | Dynamic Programming | time out |
Sherlock and Cost | O(N) | O(N) | Moderate | Dynamic Programming | |
Hexagonal Gird | O(N^2) | O(N) | Moderate | Dynamic Programming | recursive solution |
Sam and SubStrings | O(N) | O(N) | Moderate | Dynamic Programming | |
Travel Around the World | O(N) | O(N) | Moderate | Dynamic Programming | validation pass and candidates finding pass |
Red John is Back | O(N) + O(nlgn) | O(N) | Moderate | Dynamic Programming | memoization |
Dorsey Thief | O(NM) | O(NM) | Advanced | Dynamic Programming |
Data Structures in HackerRankHelper
- FIFO Queue with Two Arraies
- FIFO Queue with Listnode
- ListNode
- AVLNode
- AVLTree
- BinaryIndexedTree
I created class for each problem. If you want to test those solution on HackerRank, please follow this guideline.
-
create a constant with class name.
let mySolution = MyClass()
-
call solution method on that constant
mySolution.solution()
-
copy and paste related helper methods from HackerRankHelper folder, eg. getLine(), getInt()
All those solution I wrote used Swift1.2, since HackerRank only supports Swift1.* for now. But it is not a big deal since those solutions usually don't need too much new language features.