using System.Collections.Generic;using System;publicclassProgram{publicstaticvoidMain(){varinputList=newList<int>(){1,4,5,6,7,8};varresult= FindTwoSum(inputList,12);
Console.WriteLine("List of Indexes");
result.ForEach(tuple => System.Console.WriteLine(tuple.Item1 +" and "+ tuple.Item2));}/* Write a function that, given a list and a target sum, returns zero-based indexes of all two distinct elements whose sum is equal to the target sum. */publicstaticList<Tuple<int,int>>FindTwoSum(List<int>list,intsum){intfirtIndex=0;intsecondIndex=0;inttotal=0;List<Tuple<int,int>>listOfIndex=newList<Tuple<int,int>>();for(inti= firtIndex;i< list.Count;i++){secondIndex+=1;for(intz= secondIndex;z< list.Count;z++){total= list[i]+ list[z];if(total==sum){vartuple= Tuple.Create<int,int>(i, z);
listOfIndex.Add(tuple);}}}if(listOfIndex.Count ==0)returnnull;returnlistOfIndex;}}
About
Write a function that, given a list and a target sum, returns zero-based indexes of all two distinct elements whose sum is equal to the target sum.