Skip to content

Commit 082d906

Browse files
author
Partho Biswas
committed
1296_Divide_Array_in_Sets_of_K_Consecutive_Numbers
1 parent 63b8f02 commit 082d906

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ BFS, DFS, Dijkstra, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spa
641641
|17| **[68. Text Justification](https://tinyurl.com/r7bzsul)** | [Python](https://tinyurl.com/wu6rdaw/68_Text_Justification.py)| [Vid 1](https://tinyurl.com/jkx2usg), [Vid 2](https://tinyurl.com/wd7rja2), [Vid 3](https://tinyurl.com/qlbsfqf), [Art 0](https://tinyurl.com/u5r5cuy), [Art 1](https://tinyurl.com/s84dym2) | Hard | TODO: Check again later. Very Important |
642642
|18| **[134. Gas Station](https://tinyurl.com/skyh4lj)** | [Python](https://tinyurl.com/wu6rdaw/134_Gas_Station.py), [Python](https://tinyurl.com/wu6rdaw/134_Gas_Station.py), [Swift](https://tinyurl.com/wuja3c4/134_Gas_Station.swift) | [Vid 1](https://tinyurl.com/qq8xf4v), [Art 1](https://tinyurl.com/ss9sxju) | Medium | TODO: Check again later. Very Important |
643643
|19| [1288. Remove Covered Intervals](https://tinyurl.com/wc72tcx) | [Python](https://tinyurl.com/wu6rdaw/1288_Remove_Covered_Intervals.py)| [Art 1](https://tinyurl.com/vpp5hnx) | Medium | **Line Swap with Greedy**. A must read solution. A gold mie, learned a lot |
644+
|20| [1296. Divide Array in Sets of K Consecutive Numbers](https://tinyurl.com/ycfysu46) | [Python](https://tinyurl.com/wu6rdaw/1296_Divide_Array_in_Sets_of_K_Consecutive_Numbers.swift.py), [Swift](https://tinyurl.com/wuja3c4/1296_Divide_Array_in_Sets_of_K_Consecutive_Numbers.swift.swift)| [Art 1](https://tinyurl.com/ybwhyztk) | Medium | --- |
644645

645646
</p>
646647
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Foundation
2+
3+
class Solution {
4+
func isPossibleDivide(_ nums: [Int], _ k: Int) -> Bool {
5+
var counter: [Int:Int] = [:]
6+
nums.forEach { num in
7+
counter[num, default: 0] += 1
8+
}
9+
print(counter)
10+
let sortedKeys = counter.keys.sorted()
11+
for key in sortedKeys {
12+
if counter[key] ?? 0 > 0 {
13+
let minus = counter[key]
14+
for i in key..<(key + k) {
15+
if counter[i] == nil || counter[i]! < minus! {
16+
return false
17+
}
18+
counter[i]! -= minus!
19+
}
20+
}
21+
}
22+
return true
23+
}
24+
}
25+
26+
27+
/*
28+
nums = [1,2,3,3,4,4,5,6], k = 4
29+
counter = [
30+
1:1
31+
2:1
32+
3:2
33+
4:2
34+
5:1
35+
6:1
36+
]
37+
38+
nums.sort
39+
40+
*/

0 commit comments

Comments
 (0)