AMAZON Coding Question β Solved
There are m cities in a 1-dimensional country, where each city is represented by an integer between 1 through m. There are n Amazon warehouses, where the ith warehouse can deliver to cities in the
range cityStart[i] to cityEnd[i] for better delivery management.
For example, if there are m = 10 cities, and n = 2 warehouses cityStart = [3, 1] and cityEnd = [10, 5] then the first warehouse delivers to cities from 3 to 10 and the second one delivers from cities 1 to 5. Thus the cities 3, 4, and 5 are served by 2 warehouses and all others are served by exactly one.
Define F(x) as the number of warehouses that can deliver to the xth city. The growth coefficient is F(1)^F(2) .... F(m-1)^F(m), where "A" is the bitwise XOR operator.
Given the delivery ranges of all the Amazon warehouses, find Amazon's growth coefficient.
Note: The bitwise XOR operator (^) returns a 1 in each bit position for which the corresponding bits of either but not both operands are 1s.
. 12 = 00001100 (In Binary)
. 25 = 00011001 (In Binary)
. Bitwise XOR Operation of 12 and 25
00001100 00011001 = 00010101 = 21 (In decimal)
Example
cityStart = [1,1, 2]
cityEnd = [1, 3, 4]
m=4
In the above example, the number of cities m = 4 and the number of warehouses n = 3.