Last active
June 14, 2017 04:23
-
-
Save tlkahn/01c304891e5aa6d7562feb0857a81811 to your computer and use it in GitHub Desktop.
hackerland-radio-transmitters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(k, arr, origin=0): | |
| arr.sort() | |
| result = 1 | |
| cur = 0 | |
| origin = 0 | |
| for i in range(1, len(arr)): | |
| if arr[i] - arr[origin] <= k: | |
| pass | |
| else: | |
| origin = i - 1 | |
| j = 1 | |
| while origin + j < len(arr): | |
| if arr[origin + j] - arr[origin] <= k: | |
| pass | |
| else: | |
| origin = origin + j | |
| i = origin + j + 1 | |
| result += 1 | |
| continue | |
| j += 1 | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment