#75 Median Vehicle Model Year by Region
For a dataset of vehicles consisting of a registration plate and model year, calculate the median model year for each region:
class Car {
public final String id;
public final int year;
public Car(String id, int year) {
this.id = id;
this.year = year;
}
}
class App {
public static void main(String[] args) {
List<Car> cars = Arrays.asList(
new Car("а123мс177", 1999),
new Car("м773ау99", 2002),
new Car("о564ау177", 2010),
new Car("о444ук177", 2021),
new Car("а111но99", 2004)
);
}
public Map<Integer,Integer> calculateMedian(List<Car> cars) {
...
}
}
For example, the following should be printed for these vehicles:
99 - 2003
177 - 2010
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor