# TwoSum

C# Algorithmic thinking Searching Public

Easy

30min

Write a function that, given a list and a target sum, returns zero-based indices of any two distinct elements whose sum is equal to the target sum. If there are no such elements, the function should return null.

For example, FindTwoSum(new List<int>() { 1, 3, 5, 7, 9 }, 12) should return a Tuple<int, int> containing any of the following pairs of indices:

• 1 and 4 (3 + 9 = 12)
• 2 and 3 (5 + 7 = 12)
• 3 and 2 (7 + 5 = 12)
• 4 and 1 (9 + 3 = 12)
C# 7.0, .NET Framework 4.7

•   Example case: System.NotImplementedException at TwoSum.FindTwoSum(IList`1 list, Int32 sum) in TwoSum.cs:line 8
•   No solution: System.NotImplementedException at TwoSum.FindTwoSum(IList`1 list, Int32 sum) in TwoSum.cs:line 8
•   One solution: System.NotImplementedException at TwoSum.FindTwoSum(IList`1 list, Int32 sum) in TwoSum.cs:line 8
•   Performance test with a large number of elements: System.NotImplementedException at TwoSum.FindTwoSum(IList`1 list, Int32 sum) in TwoSum.cs:line 8