Minimum Common 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 two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.
Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.
LeetCode Problem - 2540: Link | Click Here
import java.util.HashSet;
class Solution {
// Method to find a common element in two arrays
public int getCommon(int[] nums1, int[] nums2) {
// Create a HashSet to store elements of the first array
HashSet<Integer> hs1 = new HashSet<>();
// Populate the HashSet with elements from the first array
for (int e : nums1) {
hs1.add(e);
}
// Initialize the result variable to indicate no common element found
int result = -1;
// Iterate through the elements of the second array
for (int j : nums2) {
// Check if the HashSet contains the current element from the second array
if (hs1.contains(j)) {
result = j; // Update the result with the common element
break; // Break the loop once a common element is found
}
}
// Return the common element or -1 if no common element is found
return result;
}
}




