Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Algorithms/Implementation/Beautiful Triplets/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int d = input.nextInt();

List<Integer> arr = new ArrayList<>(); // to add all Array Elements as It will be used Later
Set<Integer> values = new HashSet<>();

int beautifulTriplets = 0;
Expand All @@ -20,7 +20,7 @@ public static void main(String[] args) {
for(int i = 0; i < n; i++)
{
int x = input.nextInt();

arr.add(x);
if(!values.contains(x))
{
values.add(x);
Expand All @@ -29,7 +29,7 @@ public static void main(String[] args) {


//Check if set has a value, value+d, and value + 2d
for(Integer digit : values)
for(Integer digit : arr) // use " arr " in place of " values " as if the input Value have any Repetition it need to be Counted.
{
if(values.contains(digit+d) && values.contains(digit+(2*d)))
{
Expand All @@ -39,4 +39,4 @@ public static void main(String[] args) {

System.out.println(beautifulTriplets);
}
}
}