Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

Uber Interview Problem

Revision en1, by D_Coder_03, 2020-08-06 23:08:13

PROBLEM STATEMENT :

You have given 4 numbers A, B, C, D and you have to perform an algorithm:-

int sum=0;

for(int i=A;i<=B;i++) {

for(int j=C;j<=D;j++)
    sum+=i^j;

}

As the sum could be very large, compute it modulo 1000000007 (10e9+7).

Constraints : 1<=A,B,C,D<=1000000000

Time Limit — 1 sec

INPUT :- 4 integers A,B,C,D is given.

OUTPUT :- Print the sum after performing the algorithm.

EXAMPLE INPUT:- 1 2 3 4

EXAMPLE OUTPUT:- 14

EXPLANATION :- 1^3+1^4+2^3+2^4

2 + 5 + 1 + 6 = 14

This problem was asked in my recent coding round of Uber. Can anyone help me with its approach?

Tags xor properties, xor-sum

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English D_Coder_03 2020-08-06 23:08:13 693 Initial revision (published)