Loading...
Loading...
Loading...
Java · References, Casting & Immutability
A booking app stores each seat as record Seat(String coach, int number). Two bookings clash when they are for the same coach and the same seat number. Count the bookings that repeat a seat booked earlier, comparing seats with equals().
B2) and a seat number.Clashes <count>.Example
Input
5 B2 14 B3 14 B2 14 S1 7 B2 14
Output
Clashes 2
The third and the fifth bookings repeat B2 14.
Try the problem first. Open one hint at a time.
A record's generated equals() compares every component, so new Seat("B2", 14).equals(new Seat("B2", 14)) is true.
For booking i, look back at bookings 0 to i − 1; count i once if any of them is equal.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor