Techno Blender
Digitally Yours.
Browsing Tag

Subarray

Maximizing Subarray sum with constrained traversal and addition time

Given two integers N and M representing the Length of arr  and number of seconds. The task is to maximize the sum of the subarray where it takes 0.5secs to travel in consecutive elements and 0.5secs to add a value of the element in sum. It is given that one can start from any element.Example:Input: N = 7, M = 3, arr = { 2, 1, 3, 5, 0, 1, 4 }Output: 9Explanation:  One can start from index 1 and move to index 2 and then to index 3. Hence, the total sum is  = 1 + 3 + 5 = 9.Input: N = 6, M = 2, arr = { 1, 6, 2, 5, 3, 4…

Longest alternating Subarray with absolute difference at least K

Given an array arr of size N and integer K, the task is to find the longest subarray that has alternating even and odd integers such that the absolute difference between the first and last element of the subarray is greater than or equal to K.Examples:                                                                                                                                                                                                                                      Input:  N = 6, K = 3, array = {2, 5, 4, 7, 8,…

Max sum of Subarray of length N/2 where sum is divisible by N

Given an array, arr of size N where N is even, the task is to find the maximum possible sum of the subarray of length N/2 where the sum is divisible by N.Examples:Input: arr = {2, 3, 4, 5, 6, 7}, N = 6Output:18Explanation: Here, N = 6, The maximum possible sum of a sublist of length 3 (N/2) is 18 (divisible by 6), which can be obtained by selecting the subarray .Input: arr = {3, 5, 6, 11, 7, 8}, N = 6Output: 24Explanation: The maximum possible sum of a sublist of length 3 (N/2) is 24 (divisible by 6), which can be…

Find the longest Subarray with equal Sum and Product

Given an array arr of N integers, the task is to find the length of the longest subarray where the sum of the elements in… Read More The post Find the longest Subarray with equal Sum and Product appeared first on GeeksforGeeks. Given an array arr of N integers, the task is to find the length of the longest subarray where the sum of the elements in… Read More The post Find the longest Subarray with equal Sum and Product appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original article here Denial…

Check if there exists any subarray with the given conditions

Given two integers N and X. Then the task is to return YES or NO by checking whether there exists a subarray in any permutation of length N such that it contains a subarray, where A*B is equal to the X. Here A and B denote the number of elements in sub-array and the first element of sorted subarray respectively.Examples:Input: N = 5, X = 3Output: YESExplanation: Considered the permutation is: {5, 2, 1, 3, 4}. Take the sub-array {A4. . . .A4} = { 3 }. Then A = 1 (As only 1 element is there), B = 3 (If the sub-array is…

Check if sum of Subarray of a 2D Array is in Increasing order

Given a 2d Array arr, the task is to check if the sum of the subarrays is in increasing order or not. If yes return… Read More The post Check if sum of Subarray of a 2D Array is in Increasing order appeared first on GeeksforGeeks. Given a 2d Array arr, the task is to check if the sum of the subarrays is in increasing order or not. If yes return… Read More The post Check if sum of Subarray of a 2D Array is in Increasing order appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original article here…

Maximum sum of at most K non-overlapping Subarray

Given an array, arr of size N, the task is to find the sum of the at most K non-overlapping contiguous subarray within an arr… Read More The post Maximum sum of at most K non-overlapping Subarray appeared first on GeeksforGeeks. Given an array, arr of size N, the task is to find the sum of the at most K non-overlapping contiguous subarray within an arr… Read More The post Maximum sum of at most K non-overlapping Subarray appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original article here…

Find Subarray whose end points don’t have maximum or minimum

Given an array nums of length N which contains integers, the task is to find a subarray such that the first and the last element… Read More The post Find Subarray whose end points don’t have maximum or minimum appeared first on GeeksforGeeks. Given an array nums of length N which contains integers, the task is to find a subarray such that the first and the last element… Read More The post Find Subarray whose end points don’t have maximum or minimum appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE…

Maximum XOR subarray of K distinct integer

Given an array A consisting of N positive integers, the task is to calculate the maximum XOR of the subarray of size K consisting of all distinct integers. If such subarray is not present then Print “-1”.Examples:Input: N = 10, A = , K = 4Output: 9Explanation : All Subarrays of size K with all distinct integers are , , and there XOR are 6, 5, 9 respectively. So Maximum XOR of subarray is 9. Input: N = 5, A = , K = 3Output: -1Explanation: Since there of no subarray of size K with all integers distinctNaive Solution: The…

Find maximum sum by replacing the Subarray in given range

Given an array arr, the task is to find the maximum sum possible such that any subarray of the indices from i.e all subarray elements from arr to arr can be replaced with |arr – arr| any number of times.Examples:Input: arr = { 9, 1}Output: 16Explanation: The subarray can choose as so it can be replaced as { | 9 – 1 |, | 9 – 1 | } = {8, 8} this is the only array that gives the maximum sum as 16.Input: arr = {1, 1, 1}Output: 3Explanation: The array from indices can be chosen then the array becomes {1, |1 – 1|, |1 – 1| }…