Given an array of N unique numbers. Also given two numbers a and b such that a will always be before b in the array. The task is to find the sum of the array elements excluding the elements which lie between a and b.
Input : arr = [2, 1, 6, 9, 11], a = 6, b = 9
Output : 14
Input : arr = [1, 2, 4, 5, 6], a = 2, b = 5
Output : 7
Approach: Traverse in the array, keep adding the array elements until we find a. Continue iteration until b is found and do not add array elements to the sum. After b is found, add array elements to the sum till the end. Once the iteration is completed, return the sum.
Below is the implementation of the above approach:
- Maximum Subarray Sum Excluding Certain Elements
- Average of remaining elements after removing K largest and K smallest elements from array
- Elements to be added so that all elements of a range are present in array
- Find elements larger than half of the elements in an array
- Count number of elements between two given elements in array
- Find elements of array using XOR of consecutive elements
- Maximize the sum of X+Y elements by picking X and Y elements from 1st and 2nd array
- Find all elements in array which have at-least two greater elements
- Count array elements that divide the sum of all other elements
- Minimum elements to change so that for an index i all elements on the left are -ve and all elements on the right are +ve
- Rearrange array such that even index elements are smaller and odd index elements are greater
- Equal sum array partition excluding a given element
- Find original array from encrypted array (An array of sums of other elements)
- Program to print elements of a Matrix row-wise skipping alternate elements
- Count elements such that there are exactly X elements with values greater than or equal to X
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.