Given an array print sum of the pairwise consecutive elements.
Input : 8, 5, 4, 3, 15, 20 Output : 13, 9, 7, 18, 35 Input : 5, 10, 15, 20 Output : 15, 25, 35
The solution is to traverse the array and saving the sum of consecutive numbers in the variable sum.
14 25 20 11
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count array elements that can be represented as sum of at least two consecutive array elements
- Replace array elements by sum of next two consecutive elements
- Minimum score possible for a player by selecting one or two consecutive array elements from given binary array
- Find last two remaining elements after removing median of any 3 consecutive elements repeatedly
- Maximize the sum of differences of consecutive elements after removing exactly K elements
- Minimize the sum of differences of consecutive elements after removing exactly K elements
- Generate original array from difference between every two consecutive elements
- Rearrange an array such that product of every two consecutive elements is a multiple of 4
- Find elements of array using XOR of consecutive elements
- Rearrange an array to minimize sum of product of consecutive pair elements
- Check if there exist two elements in an array whose sum is equal to the sum of rest of the array
- Construct an array from GCDs of consecutive elements in given array
- Check if N can be represented as sum of squares of two consecutive integers
- Find minimum sum such that one of every three consecutive elements is taken
- Minimum sum subsequence such that at least one of every four consecutive elements is picked
- Smallest subsequence with sum of absolute difference of consecutive elements maximized
- Maximum subsequence sum such that no K elements are consecutive
- Minimize the sum calculated by repeatedly removing any two elements and inserting their sum to the Array
- Check if array elements are consecutive | Added Method 3
- Remove minimum elements from array such that no three consecutive element are either increasing or decreasing
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.
Improved By : jit_t