Company: Zeta

Difficulty: medium

Problem Statement

Pair Hunting You are given two 1-indexed integer arrays A and B, each of size N, and an integer K. A pair (i, j) with 1 Increase A[i] by K. Let X = A[i] - A[j] and Y = B[i] - B[j] under this change. If X Increase B[i] by K. Let X = A[i] - A[j] and Y = B[i] - B[j] under this change. If X Report how many good pairs exist. Input Format The first line contains two integers N and K. The second line contains N integers A[1], A[2], ..., A[N]. The third line contains N integers B[1], B[2], ..., B[N]. Output Format Print the number of good pairs. Constraints 2 ≤ N ≤ 10 5 -10 4 ≤ K ≤ 10 4 -10 4 ≤ A[i], B[i] ≤ 10 4 Examples Input: 4 2 1 2 3 4 5 6 7 8 Output: 6 Explanation: Every possible pair among the four indices turns out to be good: (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4). Code Template #include <bits/stdc++.h> using namespace std; class Solution { public: long long goodPairHunting(vector<int> &A, vector<int> &B, int K) { // Write your code here } }; int main() { int

More Zeta OA questionsInterview experiences