#409 Implementing SQL JOIN for Lists

Companies:
2GIS
Themes:
JavaCollections & GenericsPractice

The comments contain an SQL query. Implement an equivalent of this query in the join() method.

public class MainJava {
    /*
    SELECT
        left.K,
        left.V1,
        right.V2
    FROM left
    JOIN right ON left.K = right.K;
    */
    public <K extends Comparable<K>, V1, V2> List<Triple<K, V1, V2>> join(List<Pair<K, V1>> left, List<Pair<K, V2>> right) {
        return null; // code here
    }

    private static class Pair<A, B> {
        private A first;
        private B second;

        Pair(A first, B second) {
            this.first = first;
            this.second = second;
        }
    }

    private static class Triple<A, B, C> {
        private A first;
        private B second;
        private C third;

        Triple(A first, B second, C third) {
            this.first = first;
            this.second = second;
            this.third = third;
        }
    }
}

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