Yahoo India Web Search

Search results

  1. May 28, 2024 · Pair with given Sum (Two Sum) - GeeksforGeeks. Last Updated : 28 May, 2024. Given an array A [] of n numbers and another number x, the task is to check whether or not there exist two elements in A [] whose sum is exactly x. Examples: Input: arr [] = {0, -1, 2, -3, 1}, x= -2. Output: Yes.

  2. leetcode.com › problems › two-sumTwo Sum - LeetCode

    Two Sum - Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

  3. class target_sum { static int[] targetSum(int []a , int target) { int left = 0 , right = a.length - 1 , tempSum; while(left < right) { tempSum = a[left] + a[right]; if(tempSum == target) return new int[]{left + 1 , right + 1}; if(tempSum > target) right--; else left++; } return new int[]{-1 , -1}; } public static void main(String args[]) { int ...

  4. Jul 8, 2024 · Count pairs with given sum. Given an array of N integers, and an integer K, the task is to find the number of pairs of integers in the array whose sum is equal to K. Examples: Explanation: Pairs with sum 6 are (1, 5) and (7, -1).

  5. Apr 22, 2024 · In this tutorial, we'll explore different techniques to find pairs in an array whose sum equals a given target value. From the brute-force approach to more efficient methods using hashing or sorting, you'll learn how to tackle this common problem with ease.

  6. Two Sum II - Input Array Is Sorted - Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length.

  7. 1. Two Sum. Easy Array Hash Table. Leetcode Link. Problem Description. In this problem, we have an array of integers called nums and a target integer called target. Our task is to find two distinct numbers within the array that when added together, equal the target.

  8. Feb 22, 2022 · Two Sum problem is a classic problem and this has been listed first as one of the basic questions one has to solve when prepping for coding interviews.

  9. You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum. Input Format: The first line of input contains T denoting the number of testcases

  10. Apr 25, 2022 · Companies like Google and Facebook like to ask prospective job candidates to tackle the two-sum problem. This primer will help you learn how to handle it. Can't find your company?

  1. People also search for