## Interview Question

Senior Operations Developer, Interview

-Vancouver, BC

# write a c# method to bring pairs of integers that sum up to 10 from an array of integers.

1

using System; using System.Collections.Generic; namespace pairsSum { class Program { public static Dictionary myPairs(int [] myArr, int sumUp){ Dictionary returnPair = new Dictionary (); int len = myArr.Length; Console.WriteLine("Array Size -> "+len); for (int i=0;i myDictionary = myPairs(myArray,10); foreach (var item in myDictionary) { Console.WriteLine("key {0} and value {0}",item.Key,item.Value); } } } }

C# on

0

They said the solution should have to sorted the integer array, put two pointers at the end and front compare the sum of a and b, if it was more than 10 then bring the last pointer forward until end of array ... They best solution was (On), and I gave them( lgn)... The other solution was to build a dictionary with pairs and each time adding new element check to see if it already exited ... #include #include #include static std::map findPairsOfSum(int array[], int sum){ std::map myPair; int len = sizeof(array); if (array == NULL) return myPair; for (int i=0; i pairs; int myArray[] = {0,10,3,7,3,5,7,3}; pairs = findPairsOfSum(myArray,10); // printing map std::map :: iterator it; for (it = pairs.begin(); it != pairs.end(); ++it){ std::coutfirstsecond myPairs(int [] myArr, int sumUp){ Dictionary returnPair = new Dictionary (); int len = myArr.Length; Console.WriteLine("Array Size -> "+len); for (int i=0;i myDictionary = myPairs(myArray,10); foreach (var item in myDictionary) { Console.WriteLine("key {0} and value {0}",item.Key,item.Value); } } } }

Anonymous on

0

#include #include #include static std::map findPairsOfSum(int array[], int sum){ std::map myPair; int len = sizeof(array); if (array == NULL) return myPair; for (int i=0; i pairs; int myArray[] = {0,10,3,7,3,5,7,3}; pairs = findPairsOfSum(myArray,10); // printing map std::map :: iterator it; for (it = pairs.begin(); it != pairs.end(); ++it){ std::coutfirstsecond <<'\n'; } return 0; }

C++ on