Find Lucky Integer In an Array

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.
Q - Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.
Return the largest lucky integer in the array. If there is no lucky integer return -1.
LeetCode Problem: Link | Click Here
class Solution {
public int findLucky(int[] arr) {
// Store the length of the array
int arrLen = arr.length;
// Initialize the finalCount variable to -1
int finalCount = -1;
// Iterate through the array elements
for (int i = 0; i < arrLen; i++) {
// Initialize count for the current element to 0
int count = 0;
// Count occurrences of the current element in the array
for (int j = 0; j < arrLen; j++) {
if (arr[i] == arr[j]) {
count++;
}
}
// Check if the count matches the value of the element and is greater than the current finalCount
if (count == arr[i] && arr[i] > finalCount) {
// Update finalCount to the value of the current element
finalCount = arr[i];
}
}
// Return the final lucky number found
return finalCount;
}
}




