Smallest Index With Equal Value

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.
Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
x mod y denotes the remainder when x is divided by y.
LeetCode Problem - 2057
class Solution {
public int smallestEqual(int[] nums) {
// Initialize answer with a very large value (maximum integer value)
int answer = Integer.MAX_VALUE;
// Flag to check if any matching index is found
boolean flag = true;
// Iterate through the array to find the smallest index that satisfies the condition
for(int i = 0; i < nums.length; i++) {
int mod = i % 10; // Calculate i modulo 10 (i % 10) to compare with nums[i]
// If the modulo result matches the current element in the array
if(mod == nums[i]) {
// If the current index is smaller than the previously found answer, update answer
if(i < answer) {
answer = i; // Update answer with the current index
flag = false; // Set flag to false as a matching index is found
}
}
}
// If no matching index is found, return -1
if(flag) return -1;
// Return the smallest index that satisfies the condition
return answer;
}
}




