Question: Given a route in a straight line. N buses operate between various bus stations. There is a workstation at the start of the route. The
Given a route in a straight line. N buses operate between various bus stations. There is a workstation at the start of the route. The distances of the bus stations from the workstation are calculated. The transportation authority wishes to decrease the number of buses that it operates in the city. If any buses are found to have overlapping routes, then these buses will be replaced by a single bus.
The authority wishes to determine how many buses will remain after the buses with overlapping routes have been eliminated.
Write an algorithm to find how many buses will remain after the buses with overlapping routes have been eliminated.
Input
The first line of the input consists of two spaceseparated integers busStationrow and busStationcol, representing the number of buses running on the route N and number of bus stations for each bus showing the starting and ending bus stations M
The next N lines consist of M spaceseparated integers representing the distance of the starting and ending bus stations of N buses from the workstation.
Output
Print an integer representing how many buses will remain after the buses with overlapping routes have been eliminated.
Constraints
busStationrow
busStationsi busStationsi busStations are the starting and ending bus stations of a bus.
O si busStationrow
Example
Input:
Output:
complete method public static int busRemainingint busStation
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
