This is a repo for HackerRankSolutions with Swift
Alternatives To Hackerranksolutions
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Interactive Coding Challenges26,246
6 months ago70otherPython
120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
19 hours ago1February 17, 2022cc-by-sa-4.0Java
😏 LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Awesome Competitive Programming10,905
a month ago24cc-by-4.0
:gem: A curated list of awesome Competitive Programming, Algorithm and Data Structure resources
4 months ago19gpl-3.0Java
Algorithms, 4th edition textbook code and libraries
8 days ago5mitJavaScript
Metarhia educational program index 📖
Free Programming Resources2,292
3 months ago3mitHTML
💎 免费的编程资源大全,持续更新!🔥 覆盖各种语言和方向(Java \ Python \ C++ \ JavaScript \ Golang \ 前端 \ 后端等)的学习路线、贴心教程、项目实战、编程书籍、面试合集、实用资源等,对程序员非常有帮助!
Cs Books2,185
3 years ago
📚 Computer Science Books 计算机技术类书籍 PDF
4 months ago224gpl-3.0C++
It is a repository that is a collection of algorithms and data structures with implementation in various languages.
Awesome Interview2,123
a month ago46otherHTML
剑指前端 Offer
Competitive Programming Library2,038
a year ago24cc-by-4.0Java
Code library for competitive programming purposes.
Alternatives To Hackerranksolutions
Select To Compare

Alternative Project Comparisons



Language Build Status Codewake

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 Score Max Score
Angry Professor O(n) Easy Implementation 20.0 20.0
SherlockAndTheBeast O(n) Easy Implementation 30.0 30.0
Utopian Tree O(n) Easy Implementation 20.0 20.0
Find Digits O(n) Easy Implementation 25.0 25.0
Funny String O(n) Easy String 25.0 25.0
Pangrams O(n) O(1) Easy String 20.0 20.0
Alternating Characters O(n) O(1) Easy String 20.0 20.0
Game of Thrones O(n) O(1) Easy String 30.0 30.0
Make it anagram O(n) O(1) Easy String 30.0 30.0
Anagram O(n) O(1) Easy String 14.29 25
Two Strings O(n) O(1) Moderate String Set 20.0 25.0
SherlockAndAnagrams O(n^3lgn) O(n^2) Moderate String Sort, Dictionary, Permutation 4.55 50.0
Palindrome Index O(n) O(1) Easy String 25.0 25.0
Sherlock And Valid String O(n) O(1) Difficult String Dictionary 100.0 100.0
Common Child O(n^2) O(n^2) Difficult String Dynamic Programming 50.0 60.0
The Maximum Subarray O(n) O(n) Easy Dynamic Programming 16.67 50.0
The Coin Change Problem O(MN) O(MN) Medium Dynamic Programming bottom-up table construction 60.0 60.0
Red John is Back O(N) + O(nlgn) O(N) Moderate Dynamic Programming memoization 54.17 65
Knapsack O(MN) O(MN) Moderate Dynamic Programming memoization in swift 54.06 60.0
Sam and SubStrings O(N) O(N) Moderate Dynamic Programming 40.0 40.0
The Longest Increasing Subsequence O(N^2) O(N) Advanced Dynamic Programming time out 26.67 60.0
Hexagonal Gird O(N^2) O(N) Moderate Dynamic Programming recursive solution 70.0 70.0
Sherlock and Cost O(N) O(N) Moderate Dynamic Programming 28.13 50.0
Dorsey Thief O(NM) O(NM) Advanced Dynamic Programming 52.76 85.0
Travel Around the World O(N) O(N) Moderate Dynamic Programming validation pass and candidates finding pass 120.0 120.0
Sherlock and Array O(N) O(N) Easy Search 40.0 40.0
Ice Cream Parlor O(N) O(N) Easy Search 30.0 30.0
Maximise Sum O(N) O(NlgN) Moderate Search 20.31 65.0
Missing Number O(N) O(N) Moderate Search Do you believe 0.59s overtime? 25.99 45


Data Structures in HackerRankHelper

  • FIFO Queue with Two Arraies
  • FIFO Queue with Listnode
  • ListNode
  • AVLNode
  • AVLTree
  • BinaryIndexedTree
  • Heap


I created class for each problem. If you want to test those solution on HackerRank, please follow this guideline.

  1. create a constant with class name.
let mySolution = MyClass()
  1. call solution method on that constant
  1. copy and paste related helper methods from HackerRankHelper folder, eg. getLine(), getInt()

Swift Package Manager

If you want to use this module to play with local test files, you might need to import this module. Swift Package Manager is a good tool.

Firstly, add following Package.swift to your root directory.

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url:"https://github.com/jindulys/HackerRankSolutions.git", majorVersion:1),

Secondly, when you use this module in your source file, you should:

import HRSwift

Then run swift build, and .build/debug/YourModuleName, Alright, Run!!

Contribution Guidelines

HackerRank lover, swift lover do not hesitate. There are tons of unsolved questions. If you want to contribute a little bit, please write your own swift solutions then make a pull request.

For each question, you should write your own Class in corresponding file, inside that Class define a solution method, which is used for Hackerrank submission. This module could be imported by other packages, so make your class and those usable methods public. If you want to submit solution of Algorithms --> Strings --> Gemstones, you should write your solution inside String.swift. If there is no related file for a subdomain, please create a new file.

Write a test case in HRSwiftTests.swift. You could use sample input and sample output from that question as a test.

 func testAnagram() {
     let test = Anagram()
     XCTAssert(test.solve("aaabbb") == 3, "Pass")
     XCTAssert(test.solve("ab") == 1, "Pass")
     XCTAssert(test.solve("abc") == -1, "Pass")

If you write some general code that could be used afterwards, please write them in HackerRankHelper

Make sure your solution get a reasonable score on HackerRank then pull request.

You should obey Raywenderlich Swift Style Guide

Popular Algorithms Projects
Popular Programming Projects
Popular Computer Science Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Data Structures