Answer the question
In order to leave comments, you need to log in
How to find the sum of numbers at odd positions after sorting an array?
Given an array of N numbers, how to find the sum of those numbers that will be in odd places after sorting the array?
It is clear that you can sort the array and walk through it again, but how to do it faster?
The task itself:
Answer the question
In order to leave comments, you need to log in
No way. There are methods to get a number that will stand at a given position (or numbers on a segment) in a sorted array faster than sorting (QuickSelect algorithm). It is impossible to find all the numbers in odd positions somehow faster than sorting.
Edit: If standard sorting doesn't work and L is large, then it's worth looking into radix sort. If L were relatively small, then counting sort would be the best option.
There are suspicions that the task did not appear out of nowhere.
In fact, we have only 4 input parameters here.
Theoretically, this sum should be calculated in O(1).
Try to calculate on different sets of parameters, find some patterns in the results...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question