Introduction

Greetings, programming enthusiast! In this unit, we're embarking on a thrilling numerical quest, where unidentified bridges connect the islands of data. On these bridges, we'll see hashes and bins, all converging into sets! Throughout our journey, we'll utilize the fundamental concepts of the C++ Standard Template Library (STL) std::unordered_set to formulate an optimal solution. So, fasten your seatbelt and get ready to solve problems!

Task Statement

The task for this unit is to devise a C++ function that accepts two vectors containing unique integers and returns another vector containing the elements common to both input vectors. This task provides an intriguing perspective on deriving similarities between two data sequences, a scenario commonly encountered in data comparisons and analytics.

For illustration, suppose we're given two vectors:

C++
std::vector<int> list1 = {1, 2, 3, 5, 8, 13, 21, 34};
std::vector<int> list2 = {2, 3, 5, 7, 13, 21, 31};

The common_elements(list1, list2) function should comb through these arrays of integers and extract the common elements between them.

The expected outcome in this case should be:

C++
std::vector<int> result = {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