"""
There is a building with M floors (labelled 1,2,…,M). There is one lift starting on the first floor, and going up once, till the Mth floor.
There are N passengers using the lift in this journey. The nth passenger boards at the floor entry[n] and alights at the floor exit[n], with 1<= entry[n] < exit[n] <= M. Each of these floors are considered as stops for the lift.
For each passenger, the lift may or may not stop at other floors during their travel in the lift. If there are intermediate stops, we consider each intermediate stop as an extra stop for that passenger. The goal is to find the sum of the number of extra stops for all passengers.
Input:
The first line contains two integers, M (number of floors) and N (number of passengers). Two more lines follow.
The second line contains entry floors for the N passengers.
The third line contains exit floors for the N passengers.
Output:
The output should contain a single integer, representing the total number of extra stops
Sample input:
10 6
2 7 4 5 7 8
3 9 8 7 9 10
Sample output:
5
Explanation:
The number of extra stops for each passenger is 0, 1, 2, 0, 1, and 1 respectively, and the sum is 5.
"""
Solved it using hashmap, but interview wants it done using prefix sum. Anyone can help me how can we do it using prefix sum?