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. 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

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

    Two Sum. Easy. 56.8K. Ln 1, Col 1. Case 1. Case 2. Case 3. nums = [2,7,11,15] target = 9. Source. Can you solve this real interview question? Two Sum - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

  4. Apr 13, 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. 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.

  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. 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.

  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. Jun 19, 2021 · Problem: Two Sum | LeetCode. 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.

  10. 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 ...

  1. People also search for