Computer Science, asked by drishiii, 1 month ago

given an integer array A containing N Integers. In one operation we can select any one element from the array A and increment it by 1. You need to answer Q queries in each query you are given two integers L and R you need to tell the minimum number of operation you need to perform such that the subarray of A starting from index L and ending at index R contains at least one pair of elements whose bitwise AND is strictly greater than zero​

Answers

Answered by lakkakulaprashanth79
12

Explanation:

use brute force quite easy problem

Answered by sujan3006sl
0

Answer:

Give the array [1, 4, 45, 6, 10, -8] and the total to be determined as 16.

Following array sort,

A = {-8, 1, 4, 6, 10, 45}

Now, increase "i" when the pair's total is less than the necessary sum and decrease "r" when the pair's sum is more than the necessary amount.

This is due to the fact that travelling from left to right (while also sorting the array) in order to find the number that might enhance the total of a pair when the sum is smaller than the needed sum results in "i++" and vice versa.

Initialize l = 0, r = 5

A[l] + A[r] ( -8 + 45) > 16 => decrement r. Now r = 4

A[l] + A[r] ( -8 + 10) increment l. Now l = 1

A[l] + A[r] ( 1 + 10) increment l. Now l = 2

A[l] + A[r] ( 4 + 10) increment l. Now l = 3

A[l] + A[r] ( 6 + 10) == 16 => Found candidates (return 1)

Explanation:

The approach used here is the Brute force algorithm.

Brute force algorithms are exactly what they sound like: simple solutions to problems that rely on computer power alone and exhausting all possibilities rather than using cutting-edge approaches to increase efficiency.

#SPJ3

Similar questions