Statementâ–¼
You are given two positive integer arrays, nums1
and nums2
, both of lengthÂ
i<j , andnums1[i]+nums1[j]>nums2[i]+nums2[j]
In simpler terms, the sum of two elements from nums1
must be greater than that of the corresponding elements from nums2
.
Constraints:
n= nums1.length
= nums2.length
1≤n≤103 1≤ nums1[i]
,nums2[i]
≤104
Solution
A brute force approach would involve iterating through all pairs
Compute
nums1[i]+nums1[j] .Compare it with
nums2[i]+nums2[j] .Increment a counter if the condition is satisfied.
However, this approach requires
To optimize, we can simplify the condition: