in python please:
Amazon has installed WiFi routers on the houses along a straight street. The city's buildings are arranged linearly, denoted by indices 1 to n. There are m Amazon routers, and each has a certain range associated with it. Router jinstalled at a certain building location i can only provide Internet to the buildings in the range [(i - routerRange[j]), (i + routerRange[j])] inclusive, where routerRange[j] is the range parameter of router j. A building is considered to be served if the number of routers providing Internet to the building is greater than or equal to the number of people living in it. Given a list of the number of people living in each building, the locations of the buildings where the routers will be installed and each router's range, find the number of served buildings in the city. Example buildingCount = [1, 2, 1, 2, 2] routerLocation = [3, 1] routerRange = [1, 2] There are 5 buildings with tenant counts shown in buildingCount. Routers are located in buildings 3 and 1 with ranges 1 and 2 as shown in routerLocation and routerRange. The first router is in building 3 and provides Internet to buildings in the range [2, 4]. WWW Building Building Building Bunding Building 5 The second router is in building 1 and provides Internet to buildings in the range [1, 3]. Router Bulding Building Building Building Building Router Tenant Count Building Count Served 1 1 1 Yes 2 2 2 Yes 3 2 1 Yes 4 1 2 No 5 0 2 No The table above, explained: • The number of routers providing Internet to building 1 is 1, which is equal to the number of people living here, so building 1 is served. • The number of routers providing Internet to building 2 is 2, which is equal to the number of people living here, so building 2 is served. • The number of routers providing Internet to building 3 is 2, which is greater than the number of people living here, so building 3 is served. • Building 4 only has coverage from 1 router, which is less than the number of people living there. The building is unserved. • Building 5 has no router coverage, so building 5 is unserved. The 3 served buildings are 1, 2, and 3. Return 3. Function Description Complete the function getServedBuildings in the editor below. getServedBuildings has the following parameters: int building Count[n]: buildingCount is the number of people living in building i. int routerLocation[m]: routerLocation[j] is the building where the jth router is installed. int routerRange[m]: routerRange[j] is the range parameter of the jth router. Returns int: the number of served buildings Constraints • 1≤n≤106 • 0≤ buildingCount ≤ 106 ● 0≤m≤2.105 ● 1 ≤ routerLocation[j] ≤ n • 0 ≤ routerRange[j] ≤ n ▼ Input Format For Custom Testing The first line contains an integer, n, the number of buildings in the city. Each line i of the n subsequent lines (where 0 <i< n) contains an integer, buildingCount. The next line contains an integer m, the number of elements in routerLocation[]. Each line j of the m subsequent lines (where 0 ≤j <m) contains an integer, routerLocation[j]. The next line contains an integer m, the number of elements in routerRange[]. Each line j of the m subsequent lines (where 0 ≤j <m) contains an integer, routerRange[j]. ▾ Sample Case 0 Sample Input For Custom Testing STDIN FUNCTION 4 → buildingCount[] size n = 4 2 → buildingCount = [2, 1, 1, 3] 1 1 3 2 routerLocation [] size m = 2 1 2 2 2 0 Sample Output 2 → routerLocation = [1, 2] routerRange [] size m = 2 → router Range = [2, 0]
in python please:
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am