Python3 Program for Size of The Subarray With Maximum Sum An array is given, find length of the subarray having maximum sum.Examples : Input : a[] = {1, -2, 1, 1, -2, 1}Output : Length of the subarray is 2Explanation: Subarray with consecutive elements and maximum sum will be {1, 1}. So length is 2Input : ar[] = { -2, -3, 4, -1, -2, 1, 5, -3 }Output : Leng
4 min read
Python Program for Count pairs with given sum Given an array of integers, and a number 'sum', find the number of pairs of integers in the array whose sum is equal to 'sum'. Examples: Input : arr[] = {1, 5, 7, -1}, sum = 6 Output : 2 Pairs with sum 6 are (1, 5) and (7, -1) Input : arr[] = {1, 5, 7, -1, 5}, sum = 6 Output : 3 Pairs with sum 6 are
3 min read
Python3 Program to Find if there is a subarray with 0 sum Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum.Examples : Input: {4, 2, -3, 1, 6}Output: true Explanation:There is a subarray with zero sum from index 1 to 3.Input: {4, 2, 0, 1, 6}Output: true Explanation:There is a subarray with zero s
3 min read
Python3 Program to Find the subarray with least average Given an array arr[] of size n and integer k such that k <= n.Examples : Input: arr[] = {3, 7, 90, 20, 10, 50, 40}, k = 3Output: Subarray between indexes 3 and 5The subarray {20, 10, 50} has the least average among all subarrays of size 3.Input: arr[] = {3, 7, 5, 20, -10, 0, 12}, k = 2Output: Sub
3 min read
Python3 Program to Find the K-th Largest Sum Contiguous Subarray Given an array of integers. Write a program to find the K-th largest sum of contiguous subarray within the array of numbers which has negative and positive numbers.Examples: Input: a[] = {20, -5, -1} k = 3Output: 14Explanation: All sum of contiguous subarrays are (20, 15, 14, -5, -6, -1) so the 3rd
3 min read
Python Program to get K length groups with given summation Given a list, our task is to write a Python program to extract all K length sublists with lead to given summation. Input : test_list = [6, 3, 12, 7, 4, 11], N = 21, K = 4 Output : [(6, 6, 6, 3), (6, 6, 3, 6), (6, 3, 6, 6), (6, 7, 4, 4), (6, 4, 7, 4), (6, 4, 4, 7), (3, 6, 6, 6), (3, 3, 3, 12), (3, 3,
6 min read
Python program to get all subsets having sum x We are given a list of n numbers and a number x, the task is to write a python program to find out all possible subsets of the list such that their sum is x. Examples: Input: arr = [2, 4, 5, 9], x = 15 Output: [2, 4, 9] 15 can be obtained by adding 2, 4 and 9 from the given list. Input : arr = [10,
3 min read
Python3 Program to Count triplets with sum smaller than a given value Given an array of distinct integers and a sum value. Find count of triplets with sum smaller than given sum value. The expected Time Complexity is O(n2).Examples: Input : arr[] = {-2, 0, 1, 3} sum = 2.Output : 2Explanation : Below are triplets with sum less than 2 (-2, 0, 1) and (-2, 0, 3) Input : a
3 min read
Find Number of M Contiguous Elements of a List with a Given Sum - Python The task is to find how many subsets of length m exist in a list such that their sum is equal to a given value. For example, if the input list is [1, 2, 3, 4, 5], m = 2 and the target sum is 5, the subsets [2, 3] and [1, 4] satisfy the condition. Let's go through multiple methods to solve this probl
3 min read
Python Program for Minimum product subset of an array Given an array a, we have to find the minimum product possible with the subset of elements present in the array. The minimum product can be a single element also. Examples:Â Input : a[] = { -1, -1, -2, 4, 3 } Output : -24 Explanation : Minimum product will be ( -2 * -1 * -1 * 4 * 3 ) = -24 Input : a
3 min read