func miniMaxSum(arr: [Int]) -> Void {
// Write your code here
guard arr.count > 4 else { return }
let arr = arr.sorted()
let minNums = arr.prefix(4).reduce(0, +)
let maxNums = arr.suffix(4).reduce(0, +)
print("\(minNums) \(maxNums)")
}
HackerRank - Birthday Cake Candles
func birthdayCakeCandles(candles: [Int]) -> Int {
// Write your code here
let maxHeight = candles.max() ?? 0
var freqDict = [Int: Int]()
candles.forEach { freqDict[$0, default: 0] += 1 }
let numberOfCandles = freqDict[maxHeight] ?? 0
return numberOfCandles
}
func getTotalX(a: [Int], b: [Int]) -> Int {
// Write your code here
var result = [Int]()
for i in 1...100 {
let divideEvenlyA = (a.filter({ i % $0 != 0 }).count == 0)
let divideEvenlyB = (b.filter({ $0 % i != 0 }).count == 0)
if divideEvenlyA && divideEvenlyB {
result.append(i)
}
}
return result.count
}
HackerRank - Number Line Jumps
func kangaroo(x1: Int, v1: Int, x2: Int, v2: Int) -> String {
if v1 == v2 {
if x1 == x2 { return "YES"}
return "NO"
}
let s:Float = (Float(x2) - Float(x1)) / Float(v1 - v2)
if s > 0 && s == Float(Int(s)) { return "YES"}
return "NO"
}