This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of using code for HackerRanks | |
// Input and Output array and methods | |
#import <Foundation/Foundation.h> | |
@interface Solution : NSObject | |
+ (NSArray *)calculateDeltaEncoding:(NSArray *)numbers; | |
@end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Read 2D Array of Int 5x5 | |
var arr : [[Int]] = Array(repeating: Array(repeating: 0, count: 6), count: 6) | |
for i in 0...5 { | |
arr[i] = readLine()!.characters.split(separator: " ").map{ Int(String($0))! } | |
} | |
//Read Number | |
let mealCost = Double(readLine()!)! | |
//Read Int | |
let tipPercent = Int(readLine()!)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK : This is not very elegant solution, but working with input/output is really not nice on Swift 3.1 | |
// so this just an example for working with input Sample Input like: | |
// 5 4 | |
// 1 2 3 4 5 | |
// in Arrays: Left Rotation ( | |
import Foundation | |
func rotate(arr: [Int], offset: Int) -> [Int] { | |
var newArray = [Int]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var string1 = String(readLine()!)! | |
var string2 = String(readLine()!)! | |
var count = string1.characters.count + string2.characters.count | |
var tempString1 = string1 | |
var tempString2 = string2 | |
for character in string1.characters { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// read the integer n | |
let n = Int(readLine()!)! | |
// read the array | |
var arr = readLine()!.components(separatedBy: " ").map{ Int($0)! } | |
var swapCount = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func fibonacci (n: Int) -> Int { | |
// Write your code here. | |
if (n == 0 || n == 1) { | |
return 1; | |
} | |
return fibonacci(n: n-1) + fibonacci(n: n-2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// read the integer n | |
let n = Int(readLine()!)! | |
var arr = Array(repeating: "", count: n) | |
for index in 0...n-1 { | |
arr[index] = String(readLine()!) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start of Node class | |
class Node { | |
var data: Int | |
var left: Node? | |
var right: Node? | |
init(d : Int) { | |
data = d | |
} | |
} // End of Node class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// MaxSubArray | |
// | |
// Created by Anthony Marchenko on 10/3/17. | |
// Copyright © 2017 Anthony Marchenko. All rights reserved. | |
// | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// CountInversionWithMergeSort | |
// | |
// Created by Anthony Marchenko on 10/3/17. | |
// Copyright © 2017 Anthony Marchenko. All rights reserved. | |
// | |
import Foundation |
OlderNewer