0 like 0 dislike
852 views
| 852 views

0 like 0 dislike

this approach ... Q1

``````	vector< int> a,b;
int d;

sort(b.begin(), b.end());
int res=0;
for(auto c: a){
auto i = lower_bound(b.begin(), b.end(), c-d), j = upper_bound(b.begin(), b.end(), c+d);
res+= (i==j);
}
return res;
``````
by Expert (110,880 points)
0 like 0 dislike
1. Given two integer arrays a and b, and an integer value d, your task is to find the comparator value between these arrays.

The comparator value is defined as the number of elements x ∈ a such that there are no elements y ∈ b where |x - y| ≤ d. In other words, it's the number of elements in a that are more than d away from any element of b.

Return the comparator value as an integer.

For eg. a = [2, 9] and b = [16, 13, 8], d = 3 should return 1.

n = 9
9 - 16 = 7 > 3
9 - 13 = 4 > 3
9 - 8 = 1 < 3

n = 2
2 - 16 = 14 > 3
2 - 13 = 11 > 3
2 - 8 = 6 > 3

2.

We define a subarray of size m in an n-element array to be the contiguous block of elements in the inclusive range from index i to index j, where j − i + 1 = m and 0 ≤ i ≤ j < n. For example, given array [8, 2, 4], the subarrays of size m = 2 would be [8, 2] and [2, 4] (but not [8, 4] since these elements aren't contiguous).

Given an array of integers arr, and an integer m, your task is the following:

Find the minimum value in each of the contiguous subarrays of size m;
Return the maximum value among these minimums.
Complete the maxMinInSegments function in the editor to make it return the needed value.

by Expert (110,880 points)