Count Pairs with Sum in Range

Company: Wissen

Difficulty: medium

Problem Statement

Count Pairs with Sum in Range You are given an array of integers and two integers, L and R . Your task is to count the number of pairs (i, j) such that 0 <= i < j < N and the sum arr[i] + arr[j] lies within the inclusive range [L, R] . Since the array can be large, you need an efficient solution that avoids checking all pairs naively. Implement the function countPairsInRange that takes the array length N , the integer array arr , and the two integers L and R , and returns the count of valid pairs whose sums lie in the given range. Input Format Line 1: a single integer N , the size of the array. Line 2: N space-separated integers, the elements of arr . (inferred — when N = 0 this line is present but empty) Line 3: a single integer L , the lower bound of the sum range. Line 4: a single integer R , the upper bound of the sum range. Output Format Print a single integer: the number of index pairs (i, j) with 0 <= i < j < N whose element sum lies in [L, R] . Constraints (in