Sum of two index in array & its index
Code
func getIndexFromArray(_ arr: [Int],_ target: Int) -> String {
var dic = [Int:Int]()
var output = ""
for i in 0 ..< arr.count {
dic[arr[i]] = i
let val = target - arr[i]
let final = dic[val]
if final != nil {
output = output + "\n" + "\(i),\(final ?? 0)"
}
}
return output
}