Beautiful Triplets Problem Statement
Given a sequence of integers a, a triplet(a[i], a[j], a[k]) is beautiful if:
Given an increasing sequence of integers and the value of d, count the number of beautiful triplets in the sequence.
For example, the sequence arr = [2, 2, 3, 4, 5] and d = 1. There are three beautiful triplets, by index: [i, j, k] = [0,2,3],[1,2,3],[2,3,4]. To test the first triplet, arr[j], arr[i]=3, 2=1 and arr[k], j=4, 3=1.
Beautiful Triplets Solution Code
Note: These solutions are absolutely not the most optimized and effecient one. These are very beginner style approach and was solved without prior knowledge of CS concepts like DataStructures and Algorithms that are usually taught in colleges.
0 Comments