Yahoo India Web Search

Search results

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

  2. May 28, 2024 · Two Sum using Naive Approach: The basic approach to solve this problem is by nested traversal. Traverse the array using a loop. For each element: Check if there exists another in the array with sum as x. Return true if yes, else continue. If no such pair is found, return false. Below is the implementation of the above approach:

  3. Given an array arr, and an integer k, find the number of pairs of elements in the array whose sum is k. Examples: Input: k = 6, arr[] = [1, 5, 7, 1] Output: 2 Explanation: arr[0] + arr[1] = 1 + 5 = 6 and arr[1] + arr[3] = 5 + 1 = 6.

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

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

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

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

  8. Feb 22, 2022 · Introduction. 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. Run a loop to maintain the first index of the solution in the array. Run another loop to maintain a second index of the solution for every first integer. If at any point, the sum of values of two indices is equal to the target. Print its indices.

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

  1. Searches related to two sum gfg practice

    two sum leetcode