Yahoo India Web Search

Search results

  1. 2 days ago · Learn how to find a subarray that adds to a given sum in an array of non-negative integers. See examples, code implementations, and time complexity analysis for different approaches.

  2. Jun 25, 2024 · A simple solution is to one by one consider each subarray and find its sum. If the sum is greater than k, then compare the length of this subarray with maximum length found so far. Time complexity of this solution is O (n2). An efficient solution is to use prefix sum and binary search.

  3. Jun 19, 2024 · The “Subarray Sum Equals K” problem involves finding the total number of continuous subarrays in an array that sum up to a specific target value, K. This problem is related to subarray sum...

  4. 4 days ago · Given an array arr [] of size N. The task is to find the sum of the contiguous subarray within a arr [] with the largest sum. Example: Input: arr = {-2,-3,4,-1,-2,1,5,-3} Output: 7. Explanation: The subarray {4,-1, -2, 1, 5} has the largest sum 7. Input: arr = {2} Output: 2.

    • 17 min
  5. Jun 11, 2024 · def subArrayequalsK(arr, n, k): mp = {} sum = 0 for i in range(0,n): # add current element to sum sum = sum + arr[i] # if prefix sum is equal to target if sum == k: print("Found b/w 1 and", i+1) return # If sum - sum already exists in map if (sum - k) in mp: print("Found b/w", \ mp[sum - k] + 1, "and", i+1) return mp[sum] = i+1 l = [1, 2, 3, 4 ...

  6. Hello, I was just wondering what's the difference between adding nums[i -1] and nums[i] What does this change when calculating a sum between indices…

  7. People also ask

  8. Jun 16, 2024 · Finding the largest sum subarray is a intermediate problem in coding interviews. In this guide, we'll explore how to locate the maximum sum of a continuous subarray using Kadane's Algorithm. Don't worry if this sounds complex at first—we'll break it down step by step. Go ahead and check them out!

  1. People also search for