Pertivo | onsite | Write an algorithm to find the chocolate sweetness

I'm looking for solution for the following problems,

Given the following details:

  • N denoting the number of chocolates
  • A[i] denoting the sweetness of chocolate that you have
  • B[i] denoting the lifetime (expiry duration) of chocolate that you have
  • Q queries in which each query contains two integers and

For each query, our task is to find the number of chocolates that have both sweetness
greater than X and lifetime greater than Y.

Example
If A = [4,1,23,12,3] , B = [2,4,5,1,2]

For query X = 11 , Y = 2. There exists only 1 chocolate i.e. at index 3 with a sweetness of 23
and lifetime 5. The chocolate at index 4 has sweetness 12 which is greater than X = 11
but the lifetime i.e. 1 is less than Y = 2.

Function Description
Create a function to perform the query. The function takes the following 5 parameters
and returns an integer array denoting the answer of Q queries.
N: Represents the number of chocolates
A: Represents the sweetness of the chocolate
B: Represents the lifetime of chocolate
Q: Represents the number of queries
query: Represents the query in form of two space-separated integers X and Y.

Comments (2)