Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Created January 22, 2020 12:59
Show Gist options
  • Select an option

  • Save AppleCEO/451b3a843d8b0e8d29c883a8a5c00759 to your computer and use it in GitHub Desktop.

Select an option

Save AppleCEO/451b3a843d8b0e8d29c883a8a5c00759 to your computer and use it in GitHub Desktop.
import Foundation
func solution(_ d:[Int], _ budget:Int) -> Int {
var total = 0
var count = 0
for department in d.sorted() {
if department + total <= budget {
count += 1
total += department
} else {
break
}
}
return count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment