Loading...
Loading...
A depot has drivers and buses. Several buses can have the same driver on different shifts, so a bus only points at a driver object that already exists.
Write Driver (name, rename) and Bus (number and a Driver passed to its constructor). Create each driver once and give the same object to every bus that driver drives. When a driver changes the name on record, every bus must show the new name.
busNo driverIndex (1-based). Line 3: q, then q commands rename i NEWNAME.BUS driven by NAME.Example
Input
2 Ravi Suresh 3 KA01 1 KA02 2 KA03 1 1 rename 1 Ravikumar
Output
KA01 driven by Ravikumar KA02 driven by Suresh KA03 driven by Ravikumar
KA01 and KA03 share one Driver object, so both show the new name.
Try the problem first. Open one hint at a time.
Keep the drivers in a Driver[] and pass drivers[index - 1] to each bus: never new Driver per bus.
Renaming changes the one shared object, so the buses need no update at all.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor