Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,910 views
in Online Assessments by Expert (32,020 points)

2 Answers

0 like 0 dislike
Approach:
5 pairs of (i,j): {(2,4), (2,5), (4,5), (3,5),(3,4)} satisfying the given inequality. Therefore, the answer is 5.

My approach:
Brute force, O(N^2):

for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
        if(ai-aj+c <= bi-bj+d)
           count++;
by Expert (32,020 points)
0 like 0 dislike
Q1. Count Pairs
Given 2 integer arrays, a and b and 2 integers c and d, find the pairs of i,j such that
(ai - aj+c) <= (bi - bj + d), where i<j.
Sample Test Case:
Given:
n = 5
c = 3
d = 2
Array a = [9,4,2,3,6]
Array b = [1,4,3,1,2]
by Expert (32,020 points)
...