Beautiful Triplets | HackerRank | Algorithm | Implementation | Part -1 | Python Programming | Coding

preview_player
Показать описание
This video is about "Beautiful Triplets" problem by HackerRank.
Problem:

Follow us on:
Whatsapp:
Telegram:

For 1 : 1 Tutoring
WhatsApp contact : 7278222619

Facebook:

Linkedin:

Instagram:

#BeautifulTriplets #HackerRank #Algorithms
Рекомендации по теме
Комментарии
Автор

best video on youtube for this question Thanks buddy

lovetyagi
Автор

Thanks for the great video. Another approach is we can use set to store the numbers which improves the time complexity from 0(n^2) to 0(n).
def beautiful_triplets(d: int, arr: List[int]) -> int:
arr_set = set(arr)
triplets: int = 0
for i in range(len(arr) - 2):
if arr[i] + d in arr_set and arr[i] + d * 2 in arr_set:
triplets += 1
return triplets

nischalshakya
visit shbcf.ru