#75 Median Vehicle Model Year by Region

Companies:
MegaFon
Themes:
JavaStreams & LambdasPractice

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in