Number of Arithmetic Triplets

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:
i < j < k,nums[j] - nums[i] == diff, andnums[k] - nums[j] == diff.
Return the number of unique arithmetic triplets*.*
LeetCode Problem - 2367
class Solution {
// Method to find arithmetic triplets in an array
public int arithmeticTriplets(int[] nums, int diff) {
// Initialize a variable to count the number of arithmetic triplets found
int count = 0;
// Loop through the array elements
for(int i=0; i<nums.length; i++){
// For each element, compare with all subsequent elements
for(int j=i+1; j<nums.length; j++){
// Check if the difference between the current and next element is equal to the specified difference
if(nums[j] - nums[i] == diff){
// If difference matches, look for the third element in the sequence
for(int k=j+1; k<nums.length; k++){
// Check if the difference between the next element and the current element
// in the sequence is equal to the specified difference
if(nums[k]-nums[j] == diff){
// If the third element satisfies the condition, increment the count
count++;
// Break out of the loop since we found a valid triplet
break;
}
}
}
}
}
// Return the count of arithmetic triplets found
return count;
}
}




