Created
August 23, 2020 17:40
-
-
Save bparanj/f29b3971a1aef68a83bf13d28e343ab0 to your computer and use it in GitHub Desktop.
This file contains 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
# @param {Integer[]} arr | |
# @param {Integer} a | |
# @param {Integer} b | |
# @param {Integer} c | |
# @return {Integer} | |
def count_good_triplets(arr, a, b, c) | |
count = 0 | |
size = arr.size | |
for i in (0..size-3) | |
for j in (i+1..size-2) | |
for k in (j+1..size-1) | |
if (arr[i] - arr[j]).abs <= a | |
if (arr[j] - arr[k]).abs <= b | |
if (arr[i] - arr[k]).abs <= c | |
count += 1 | |
end | |
end | |
end | |
end | |
end | |
end | |
count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment