Where 'T' denotes the number of test cases, 'N' represents the size of the array, 'TARGET' represents the sum required, and 'ARR' represents array elements. Note: You do not need to print anything it has already been taken care of. Refer to sample input/output for more clarity. If no valid pair exists, print a pair of (-1, -1). A pair (a, b) and (b, a) is the same, so you can print it in any order.Įach pair must be printed in a new line. Output Format : For each test case, print a single line containing space-separated integers denoting all pairs of elements such that they add up to the target. The second line of each test case contains ‘N’ single space-separated integers, denoting the elements of the array. IntegrityPro Consulting, LLC ServiceNow Solutions Tailored for every organization Solutions That Drive Innovation In a continuously changing world Contact Us Our Services Here’s how we can help you innovate, transform, and modernize your Enterprise with impactful solutions. The first line of each test case contains two single space-separated integers ‘N’ and ‘Target’ denoting the number of elements in an array and the Target, respectively. Input Format: The first line of input contains an integer ‘T’ denoting the number of test cases to run. Note: We cannot use the element at a given index twice.įollow Up: Try to do this problem in O(N) time complexity. Your task is to return all pairs of elements such that they add up to Target. Two Sum You are given an array of integers 'ARR' of length 'N' and an integer Target.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |