Loading...
Loading...
A railway system received n ticket records, and some bookings arrived twice, sometimes with the passenger name typed differently. A ticket is the same booking when the PNR and the seat match. Write Ticket with equals(), hashCode() and toString(), then print each booking once, at its first appearance, and the number of unique bookings.
pnr seat name (the PNR is a string of digits).PNR <pnr> seat <seat> (<name>) for each first appearance, then Unique: <count>.Example
Input
5 4521 32 Aarav 4521 33 Priya 4521 32 AaravK 7788 10 Rohan 7788 10 Rohan
Output
PNR 4521 seat 32 (Aarav) PNR 4521 seat 33 (Priya) PNR 7788 seat 10 (Rohan) Unique: 3
Line 3 repeats PNR 4521 seat 32 with another spelling, so it is skipped.
Try the problem first. Open one hint at a time.
Compare seat with == and pnr with equals(); ignore the passenger name.
For record i, look at every earlier record j < i; print record i only if none is equal.
hashCode() uses the same two fields: Objects.hash(pnr, seat).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor