Question: Amazon OA: Check Pair Sum Exists The following function returns a boolean value representing if there is a pair with given sum exists in the

 Amazon OA: Check Pair Sum Exists The following function returns a

Amazon OA: Check Pair Sum Exists The following function returns a boolean value representing if there is a pair with given sum exists in the array. The following code compiles successfully but fails to return the desired result. Your task is to fix the code so that it passes all test cases. Solve the problem: JAVAS 1, import java.util.*; 2 import java.io.*; 3 import java.lang.*; 9 - 10- public class Solution { public boolean checkPairSumExists(int rows, int cols, int[][] arr, int sum) { Set Integer set new HashSet(); for(int i = 0; i rows; i++) { for(int j = 0; ) cols; j++){ if(set.contains (sum arr[i][j])) { return true; } else { set.add(sum); } return false; } 19 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!