Dsa
Greedy
Medium
City Bike Sharing
You are tasked with designing a bike-sharing system in a city. The city has `N` stations that are interconnected, and every station has a number of bikes available. The bike-sharing demand fluctuates over a day, and you need to determine the maximum number of bikes you can maintain in service during peak demand periods without exceeding limits on each station.
Input:
The first line contains an integer `N` (the number of stations).
The next `N` lines each contain two integers: `C_i` (capacity of the station) and `D_i` (number of bikes currently demanded at that station).
Output:
Print a single integer: the maximum number of bikes that you can rent out without exceeding the capacities.
Example:
Input:
3
4 2
3 3
5 6
Output:
9
Key concepts
greedyintervalarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now