import Foundation
func removeMiddleCharacters(from str: String, count n: Int) -> String {
guard n > 0 && n < str.count else { return str }
let middleIndex = str.index(str.startIndex, offsetBy: str.count / 2)
let startIndex = str.index(middleIndex, offsetBy: -(n / 2))
let endIndex = str.index(startIndex, offsetBy: n)
var modifiedString = str
modifiedString.removeSubrange(startIndex..<endIndex)
return modifiedString
}
let str = "abc123def"
let resultString = removeMiddleCharacters(from: str, count: 3)
print(resultString)
/*
run:
abcdef
*/