public func solution(_ N : Int, _ A : inout [Int]) -> [Int] {
var array = Array(repeating: 0, count: N)
var maxValue = 0
for (_, value) in A.enumerated() {
if value <= N {
array[value-1] += 1
maxValue = array[value-1] > maxValue ? array[value-1] : maxValue
} else {
array = Array(repeating: maxValue, count: N)
}
}
return array
}
public func solution43(_ N : Int, _ A : inout [Int]) -> [Int] {
var array = Array(repeating: 0, count: N)
var maxValue = 0
var minValue = 0
for (_, value) in A.enumerated() {
//print(value, array)
if value <= N {
if array[value-1] < minValue {
array[value-1] = minValue + 1
} else {
array[value-1] += 1
}
maxValue = array[value-1] > maxValue ? array[value-1] : maxValue
} else {
minValue = maxValue
}
}
array = array.map ({ $0 < minValue ? minValue : $0 })
return array
}