AMAZON Coding Question – Solved

12 Live
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.

Asked in: AMAZON

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |