• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 06, 2024 |470 Views

PROBLEM OF THE DAY : 05/06/2024 | Swapping pairs make sum equal

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Arrays but also build up problem-solving skills.

Given two arrays of integers a[] and b[] of size n and m, the task is to check if a pair of values (one value from each array) exists such that swapping the elements of the pair will make the sum of two arrays equal.

Note: Return 1 if there exists any such pair otherwise return -1.

Example 1:

Input: n = 6, m = 4, a[] = {4, 1, 2, 1, 1, 2}, b[] = (3, 6, 3, 3)
Output: 1
Explanation: Sum of elements in a[] = 11, Sum of elements in b[] = 15, To get same sum from both arrays, we can swap following values: 1 from a[] and 3 from b[]

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/swapping-pairs-make-sum-equal4142/1