Peak guests on board
A cruise ship starts empty. Every hour some guests board and then some leave. Given the boarding and leaving counts for each hour, print the largest number of guests on board at the end of any hour.
Reported in: TCS NQT (Sep 2023) (memory-based)
Input
First line: H (hours). Second line: H boarding counts. Third line: H leaving counts.
Output
The maximum number of guests on board.
Constraints
1 ≤ H ≤ 10^5; counts never make the total negative.
Example 1
Input:
5
7 0 5 1 3
1 2 1 3 4
Output:
8Example 2
Input:
3
2 3 0
0 1 4
Output:
4Hint: Keep a running total: add the boarders, subtract the leavers, track the maximum.