Skip to content

Instantly share code, notes, and snippets.

@M-Quadra
Last active March 27, 2022 06:25
Show Gist options
  • Select an option

  • Save M-Quadra/f55f85a10a48e93119c3d79b6e893498 to your computer and use it in GitHub Desktop.

Select an option

Save M-Quadra/f55f85a10a48e93119c3d79b6e893498 to your computer and use it in GitHub Desktop.
SourceKitService Bug
import Foundation
class Solution {
func numSubarrayBoundedMax(_ nums: [Int], _ left: Int, _ right: Int) -> Int {
let arr = nums.map { v -> (Int, Int) in
switch v {
case ..<left: return (0, 0)
case left...right: return (1, 0)
default: return (0, 1)
}
}.reduce(into: [(0, 0)]) { arr, it in
arr.append((it.0 + arr.last!.0, it.1 + arr.last!.1))
}
return (1..<arr.count).reduce(0) { opt, i in
opt + (arr[i...].lastIndex(where: { it in
it.0>arr[i-1].0 && it.1==arr[i-1].1
}) ?? (i-1)) - i+1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment