34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
'''
|
|
Bob enjoys relaxing after a long day of work. Like many programmers, he's a fan of the famous drink Fantastic, which is sold at various stores around the city. The price of one bottle in store i is xi coins. Bob plans to buy the drink for q consecutive days, and for each day, he knows he will have mi coins to spend. On each day, Bob wants to know how many different stores he can afford to buy the drink from.
|
|
|
|
You are given two arrays:
|
|
|
|
An array of prices in the shops: prices = [x1, x2, x3, ..., xn] where each xi is the price of one bottle in store i.
|
|
An array of coins Bob can spend each day: coins = [m1, m2, m3, ..., mq] where each mi represents the coins Bob can spend on the i-th day.
|
|
Return number of shops where Bob will be able to buy a bottle of the drink on the i-th day.
|
|
|
|
Example 1
|
|
Input:
|
|
prices = [3,10,8,6,11]; coins = [1, 10, 3, 11]
|
|
Output:
|
|
[0, 4, 1, 5]
|
|
'''
|
|
|
|
from typing import List
|
|
|
|
class Solution(object):
|
|
def solve(self,prices:List[int], coins:List[int])->List[int]:
|
|
result = []
|
|
for m in coins:
|
|
count = sum(1 for x in prices if x <= m)
|
|
result.append(count)
|
|
return result
|
|
|
|
|
|
# Example usage:
|
|
if __name__ == "__main__":
|
|
prices = [868,987,714,168,123]
|
|
coins = [424,192,795,873]
|
|
solution = Solution()
|
|
print(solution.solve(prices, coins))
|
|
|