given an array A of size n and another array called B. B is made of array A and 2 constants x and y where Bi = x * Ai + c (i => 0,1,2, … N-1) For example, if A : {3, 1, 5, 7} and x = 1 and y =2, then B : {5, 3, 7 ,9}
question: find out how many times A (j+1), (j+2), …. (n -1) > Bj for j E {0, 1, … n-1 }
Using the sample input above A: {3,1,5,7} B: {5,3,7,9}
the answer would be 3 since when j = 0, A3 > B0 (7>5) when j = 1, A2 > B1 (5>3) and A3 > B1 (7>3)
since there are only 3 possibilities of A j+1 …. n -1 > Bj for j E {0, 1, … n-1 }, the output will be 3
is there a way to solve this with an algorithm below O(n^2)? thanks!