Skip to content

Commit f5c937c

Browse files
committed
Added public key words
1 parent 74905a7 commit f5c937c

File tree

3 files changed

+76
-34
lines changed

3 files changed

+76
-34
lines changed

Sources/DynamicProgramming.swift

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import Foundation
1010

11-
class CoinChangeProblem {
11+
public class CoinChangeProblem {
12+
public init() {}
13+
1214
func solution() {
1315
// read in N, M
1416
let metrics = getLineToArray().map {Int($0)!}
@@ -26,7 +28,7 @@ class CoinChangeProblem {
2628
// 1. dont use the mth coin
2729
// 2. use at least 1 mth coin
2830
// By constructing a table we could avoid overlapping subproblems
29-
func solveChanges(coins:[Int], coinsCounts:Int, total:Int) {
31+
public func solveChanges(coins:[Int], coinsCounts:Int, total:Int) {
3032
// 1. construct matrix to save result
3133
// - row represent total count from 0 to total
3234
// - col represent mth coin to use
@@ -49,7 +51,10 @@ class CoinChangeProblem {
4951
}
5052
}
5153

52-
class MaximumSubArray {
54+
public class MaximumSubArray {
55+
56+
public init() {}
57+
5358
func solution() {
5459
let T = Int(getLine())!
5560
for _ in 0..<T {
@@ -59,7 +64,7 @@ class MaximumSubArray {
5964
}
6065
}
6166

62-
func solve(inputs:[Int]) {
67+
public func solve(inputs:[Int]) {
6368
let maxElement = inputs.maxElement()
6469
if let maxE = maxElement where maxE < 0 {
6570
print("\(maxE) \(maxE)")
@@ -101,7 +106,10 @@ func ==(lhs: KnapSackPair, rhs: KnapSackPair) -> Bool {
101106
return lhs.itemIndex == rhs.itemIndex && lhs.capacity == rhs.capacity
102107
}
103108

104-
class Knapsack {
109+
public class Knapsack {
110+
111+
public init() {}
112+
105113
func solution() {
106114
let T = getInt()
107115
for _ in 0..<T {
@@ -114,7 +122,7 @@ class Knapsack {
114122
/**
115123
* This solution used memoization approach, which is a fantistic feature from Swift
116124
*/
117-
func solveWithMemo(N: Int, K: Int, array:[Int]) {
125+
public func solveWithMemo(N: Int, K: Int, array:[Int]) {
118126
if K == 0 {
119127
print("0")
120128
return
@@ -143,7 +151,10 @@ class Knapsack {
143151
}
144152
}
145153

146-
class LongestIncreasingSubsequence {
154+
public class LongestIncreasingSubsequence {
155+
156+
public init() {}
157+
147158
func solution() {
148159
let N = getInt()
149160
let array = getLinesToArray(N).map { Int($0)! }
@@ -155,7 +166,7 @@ class LongestIncreasingSubsequence {
155166
* LIS[i] = max(LIS)
156167
* time efficiency O(n^2)
157168
*/
158-
func solve(array:[Int]) {
169+
public func solve(array:[Int]) {
159170
let N = array.count
160171
var LIS = Array(count: N, repeatedValue: 0)
161172
LIS[0] = 1
@@ -203,7 +214,9 @@ class LongestIncreasingSubsequence {
203214
}
204215
}
205216

206-
class SherlockAndCost {
217+
public class SherlockAndCost {
218+
219+
public init() {}
207220

208221
func solution() {
209222
let T = getInt()
@@ -241,9 +254,12 @@ class SherlockAndCost {
241254
}
242255
}
243256

244-
class HexagonalGrid {
257+
public class HexagonalGrid {
258+
245259
static let nextPos = [(1, 0), (1, -1), (0, 1)]
246260

261+
public init() {}
262+
247263
func solution() {
248264
let T = getInt()
249265
for _ in 0..<T {
@@ -263,7 +279,7 @@ class HexagonalGrid {
263279
}
264280
}
265281

266-
func solve(grid:[[Int]]) {
282+
public func solve(grid:[[Int]]) {
267283
var currentGrid = grid
268284
if rec(&currentGrid) {
269285
print("YES")
@@ -305,15 +321,18 @@ class HexagonalGrid {
305321
}
306322
}
307323

308-
class SamAndSubString {
324+
public class SamAndSubString {
325+
326+
public init() {}
327+
309328
static let MOD = Int(1e9 + 7)
310329

311330
func solution() {
312331
let input = getLine()
313332
solve(input)
314333
}
315334

316-
func solve(input:String) -> Int {
335+
public func solve(input:String) -> Int {
317336
let N = input.characters.count
318337
var preSum = Array(count: N, repeatedValue: 0)
319338
preSum[0] = Int(String(input.characters.first!))!
@@ -336,7 +355,10 @@ class SamAndSubString {
336355
}
337356
}
338357

339-
class TravelAroundTheWorld {
358+
public class TravelAroundTheWorld {
359+
360+
public init() {}
361+
340362
func solution() {
341363
let metrics = getLineToArray().map { Int($0)! }
342364
let a = getLineToArray().map() { Int($0)! }
@@ -357,7 +379,7 @@ class TravelAroundTheWorld {
357379
* all of the city with need[i] == 0 is suitable start point
358380
*
359381
*/
360-
func solve(c:Int, a:[Int], b:[Int]) -> Int {
382+
public func solve(c:Int, a:[Int], b:[Int]) -> Int {
361383
let N = a.count
362384
var earthA = Array(count: 2*N, repeatedValue: 0)
363385
var earthB = Array(count: 2*N, repeatedValue: 0)
@@ -412,7 +434,10 @@ class TravelAroundTheWorld {
412434
}
413435
}
414436

415-
class RedJohnisBack {
437+
public class RedJohnisBack {
438+
439+
public init() {}
440+
416441
func solution() {
417442
let T = getInt()
418443
for _ in 0..<T {
@@ -422,7 +447,7 @@ class RedJohnisBack {
422447
}
423448

424449
// Use a way similar to fibonacci sequence
425-
func solve(n:Int) -> Int {
450+
public func solve(n:Int) -> Int {
426451
let fibOneAndFour: (Int)->Int = memoize { fibOneAndFour, n in
427452
if n>=1 && n<=3 {
428453
return 1
@@ -444,30 +469,33 @@ class RedJohnisBack {
444469
* Struct Passenger to store information like offer value and accept weight of gold
445470
* Using struct here is for sorting
446471
*/
447-
struct Passenger {
472+
public struct Passenger {
448473
let offer: Int
449474
let weight: Int
450475
}
451476

452477
extension Passenger : Hashable {
453-
var hashValue : Int {
478+
public var hashValue : Int {
454479
get {
455480
return offer.hashValue + weight.hashValue
456481
}
457482
}
458483
}
459484

460485
extension Passenger : CustomStringConvertible {
461-
var description: String { return "Passenger offer \(offer) for \(weight)grams" }
486+
public var description: String { return "Passenger offer \(offer) for \(weight)grams" }
462487
}
463488

464-
func ==(lhs: Passenger, rhs: Passenger) -> Bool {
489+
public func ==(lhs: Passenger, rhs: Passenger) -> Bool {
465490
return lhs.offer == rhs.offer && lhs.weight == rhs.weight
466491
}
467492

468493
let LOWESTNUMBER = -1 * NSIntegerMax
469494

470-
class DorseyThief {
495+
public class DorseyThief {
496+
497+
public init() {}
498+
471499
func solution() {
472500
let metrics = getLineToArray().map { Int($0)! }
473501
var array: [Passenger] = []
@@ -479,7 +507,7 @@ class DorseyThief {
479507
solve(array, c:metrics[1])
480508
}
481509

482-
func solve(array:[Passenger],c:Int)->Int {
510+
public func solve(array:[Passenger],c:Int)->Int {
483511
// sort the input array
484512
let sortedArray = array.sort { p1, p2 in
485513
if p1.offer == p2.offer {

Sources/Implementation.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import Foundation
1010

1111
// https://www.hackerrank.com/challenges/angry-professor
12-
class AngryProfessor {
12+
public class AngryProfessor {
13+
14+
public init() {}
15+
1316
func solution() -> Void {
1417
let TN = Int(getLine())!
1518
for _ in 0..<TN {
@@ -29,7 +32,10 @@ class AngryProfessor {
2932
}
3033

3134
// https://www.hackerrank.com/challenges/sherlock-and-the-beast
32-
class SherlockAndTheBeast {
35+
public class SherlockAndTheBeast {
36+
37+
public init() {}
38+
3339
func solution() -> Void {
3440
let TN = Int(getLine())!
3541
for _ in 0..<TN {
@@ -38,7 +44,7 @@ class SherlockAndTheBeast {
3844
}
3945
}
4046

41-
func cypherOutput(cypher: Int) -> String {
47+
public func cypherOutput(cypher: Int) -> String {
4248
for i in SRange(start: cypher/3*3, end:-1, step:-3) {
4349
if (cypher - i) % 5 == 0 {
4450
let fives = String(count: i, repeatedValue: Character("5"))
@@ -50,7 +56,7 @@ class SherlockAndTheBeast {
5056
}
5157
}
5258

53-
class UtopianTree {
59+
public class UtopianTree {
5460
var heights:[Int]
5561

5662
static func generatesHeights() -> [Int] {
@@ -69,7 +75,7 @@ class UtopianTree {
6975
return heights
7076
}
7177

72-
init() {
78+
public init() {
7379
heights = UtopianTree.generatesHeights()
7480
}
7581

@@ -82,8 +88,11 @@ class UtopianTree {
8288
}
8389
}
8490

85-
class FindDigits {
86-
func countN(n: String) {
91+
public class FindDigits {
92+
93+
public init() {}
94+
95+
public func countN(n: String) {
8796
let N = Int(n)!
8897
var count = 0
8998
for c in n.characters {

Sources/IndeedPrime.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import Foundation
1010

11-
class TheUltimateQuestion {
11+
public class TheUltimateQuestion {
12+
public init() {}
13+
1214
func solution() {
1315
let inputs = getLineToArray().map {Int($0)!}
1416
let addSum = (inputs.reduce(0, combine: +), "\(inputs[0])+\(inputs[1])+\(inputs[2])")
@@ -26,7 +28,8 @@ class TheUltimateQuestion {
2628
}
2729
}
2830

29-
class RelatedSpecies {
31+
public class RelatedSpecies {
32+
public init() {}
3033
func solution() {
3134
let T = Int(getLine())!
3235
for _ in 0..<T {
@@ -38,7 +41,7 @@ class RelatedSpecies {
3841
}
3942

4043
// This solution timeout
41-
func solve(a: [Int], b: [Int], N: Int) {
44+
public func solve(a: [Int], b: [Int], N: Int) {
4245
var current = 0
4346
for i in 0..<N {
4447
let currentMax = max(a[i], b[i])
@@ -59,7 +62,9 @@ class RelatedSpecies {
5962
// Divide and conquer
6063
}
6164

62-
class Gretchen {
65+
public class Gretchen {
66+
67+
public init() {}
6368
// Overtime
6469
func solution() {
6570
var parameters = getLineToArray().map {Int($0)!}

0 commit comments

Comments
 (0)