Yahoo India Web Search

Search results

  1. Dec 21, 2021 · Given an unsorted array of nonnegative integers, find a continuous subarray which adds to a given number. Examples : Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33. Output: Sum found between indexes 2 and 4. Sum of elements between indices. 2 and 4 is 20 + 3 + 10 = 33. Input: arr[] = {1, 4, 0, 0, 3, 10, 5}, sum = 7.

  2. Jul 5, 2024 · Given a 1-based indexing array arr [] of non-negative integers and an integer sum. You mainly need to return the left and right indexes (1-based indexing) of that subarray. In case of multiple subarrays, return the subarray indexes which come first on moving from left to right.

  3. Sep 20, 2022 · Given an unsorted array of integers, find a subarray that adds to a given number. If there is more than one subarray with the sum of the given number, print any of them. Examples: Input: arr [] = {1, 4, 20, 3, 10, 5}, sum = 33. Output: Sum found between indexes 2 and 4. Explanation: Sum of elements between indices.

  4. Step 1 - Take an array from the user of ' n ' elements; which refer to the non-negative integers in the main function. We can also take the sum value from the user to generate the result accordingly. Step 2 - Make a function call to find a subarray in which the sum of all the elements matches the given sum.

  5. Oct 19, 2021 · Find subarrays with a given sum in an array. Given an integer array, find subarrays with a given sum in it. For example, Input: nums [] = { 3, 4, -7, 1, 3, 3, 1, -4 } target = 7. Output: Subarrays with the given sum are. { 3, 4 } { 3, 4, -7, 1, 3, 3 } { 1, 3, 3 } { 3, 3, 1 } Practice this problem.

  6. Mar 18, 2024 · Overview. In this tutorial, we’ll talk about the problem of finding the number of subarrays with a given sum . First, we’ll define the problem and provide an example to explain it. Then, we’ll present two different approaches to solving it and work through their implementations and time complexity. 2. Defining the Problem.

  7. 3 days ago · Subarray with Given Sum is a common problem in the field of algorithmic programming and data structures. It involves finding a contiguous subarray within a one-dimensional array whose elements sum up to a given target value. This problem arises in various scenarios, such as financial analysis, data processing, and algorithm optimization.

  8. Subarray Sum Equals K - Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. A subarray is a contiguous non-empty sequence of elements within an array.

  9. Oct 8, 2021 · bool find_subarray(int arr[], int N, int required) { int sum; for (int i = 0; i < N; i++) { sum = arr[i]; for (int j = i + 1; j <= N; j++) { if (sum == required) { // subarray found from i to j-1; return true; } if (sum > required || j == N) break; sum = sum + arr[j]; } } return false; }

  10. 1. Introduction. Given an unsorted array of integers, the task is to find all subarrays with a specified sum. This problem has various applications and is frequently asked in interviews. Let’s dive deep into solving this problem efficiently using a sliding window and hash map approach. 2. Program Steps. 1.