Two Sum

Tags

C++

C++

The C++ language provides imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. Having a basic familiarity with the programming language used on the job is a prerequisite for quickly getting up to speed.

Algorithmic thinking

Algorithmic thinking

When designing and/or analyzing an algorithm or data structure, it is important to consider the performance and structure of an implementation. Algorithmic thinking is one of the key traits of a good programmer, especially one working on complex or performance-critical code.

Searching

Searching

Every programmer should be familiar with data-searching methods, as they are very common in data-analysis processes.

Public

Public

Public questions (free account) are common interview questions. They are great for practicing, or if you want to filter candidates using the classic problems.

Write a function that, when passed a list and a target sum, returns, efficiently with respect to time used, two distinctzero-based indices of any two of the numbers, whose sum is equal to the target sum. If there are no two numbers, the function should return (-1, -1).

For example, findTwoSum({ 3, 1, 5, 7, 5, 9 }, 10) should return a std::pair<int, int> containing any of the following pairs of indices: