Introduction

Greetings, adventurous coder! In this unit, we're embarking on an exciting journey through the world of numbers, where connected paths reveal patterns in data. We'll explore hashing and binning, all converging into collections! Throughout this adventure, we'll use the powerful and expressive language of Kotlin to design effective solutions. Fasten your seatbelt, and let's embark on this problem-solving expedition!

Task Statement

The task for this unit is to create a Kotlin function that takes two lists of unique integers as input and returns another list containing the elements that are common to both input lists. This task offers an intriguing look at identifying similarities between two sequences of data, a scenario frequently encountered in data comparisons and analytics.

For instance, suppose we have two lists:

Kotlin
val list1 = listOf(1, 2, 3, 5, 8, 13, 21, 34)
val list2 = listOf(2, 3, 5, 7, 13, 21, 31)

The commonElements(list1, list2) function should sift through these lists of integers and extract the common elements between them.

The expected result in this scenario would be:

Kotlin
val result = listOf(2, 3, 5, 13, 21)
Brute Force Solution and Complexity Analysis
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal