How to find a pair of numbers in an array that sum to K
2 min readMay 18, 2020
Introduction
As a fresher, when you will apply for a coding job, you might get asked to write a program to find a pair of numbers in an array that sum to K, given that only one such pair exists!
Step 1: Let’s create some test cases and put them in the main method
Step 2: Let’s write the method that will use a refMap to lookup (k minus current number), so to reduce time complexity
Step 3: Let’s write a custom validator that will test whether or not the output produced by the code is correct
Step 4: Let’s check whether all test cases have passed
Final Words
If you like this story, follow me on insta: https://www.instagram.com/stories/global.software.developers/?hl=en
If you like this story, follow me on insta: https://www.instagram.com/stories/global.software.developers/?hl=en