Giter Site home page Giter Site logo

hackerranksolutions's Introduction

HackerRankSolutions

HackerRankSolutions

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

Contests

Data Structures in HackerRankHelper

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

Usage

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
mySolution.solution()
  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(
    name:"YourModuleName",
    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

hackerranksolutions's People

Contributors

jindulys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hackerranksolutions's Issues

Objective C support

  1. Can you provide the code in objective c too.
  2. I have one code in php. Can you convert it to Objective C.

Thanks

Red John is Back

@jindulys I found bug in your Red John is Back solution.

You need to change method getBetterPrimes

replace
if length < 3 { return primes }

with
if length < 2 { return primes }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.