Find sum of 5 highest numbers in an array of 100 numbers
By : kiran.sakhare2006
Date : March 29 2020, 07:55 AM
wish of those help Use Hoare's select algorithm (or the median of medians, if you need to be absolutely certain of the computational complexity), then add the top partition (and divide by its size to get the average). This is somewhat faster than the obvious method of sorting instead of partitioning  partitioning is (O(N)) where sorting is O(N log(N) ). code :
#include <numeric>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main(){
std::vector<int> x {1, 101, 2, 102, 3, 103, 4, 104, 5, 105, 6};
auto pos = x.end()  5;
std::nth_element(x.begin(), pos, x.end());
auto sum = std::accumulate(pos, x.end(), 0);
auto mean = sum / std::distance(pos, x.end());
std::cout << "sum = " << sum << '\n' << "mean = " << mean << "\n";
return 0;
}

Make an infinite list of natural numbers pasted together and find index python
By : robert
Date : March 29 2020, 07:55 AM
hope this fix your issue You can do this sort of thing with a generator. Look at the function with yield below. code :
def natural_numbers():
n = 0
while True:
n += 1
yield n
def find_nth_character(n):
numbers = ""
gen = natural_numbers()
while len(numbers) < n:
numbers += str(gen.next())
print numbers
return numbers[n1]
def main():
print find_nth_character(15)
if __name__ == '__main__':
main()

Find the index of the highest numbers in a list
By : Nicko Martinez
Date : March 29 2020, 07:55 AM
help you fix your problem I have a list of integers and I want to find out the position of the biggest integer in my list. , you can try : code :
List<int> members = new List<int> { 312, 33, 122, 3979, 8712, 8888 };
int a = members.IndexOf(members.Max());

Python List Comprehensions For all the numbers 11000, use a list comprehension to find the highest single digit any of
By : th0br0
Date : March 29 2020, 07:55 AM
wish of those help This is my approach so far: , The order in which you use list comperhension is incorrect. Use code :
results = [max([divisor for divisor in range(1,10) if number % divisor == 0]) for number in range(1,1001) ]
[ expression for item in list if conditional ]

How to find the x consecutive numbers with the highest average in a list?
By : user1969544
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Just have a sliding window of x and look for the maximum. The comments in the code should be self explanatory. Note : Be careful while adding numbers they could be very large or your x is very high that you could run into overflow after adding numbers without dividing by x. So divide by x each time you add to sum. code :
double sum = 0;
for ( int i = 0; i < x; i++ ) {
sum += (double) ( arr[i] ) / x; //calculate the average of first `x` numbers, if your input elements are integers you need to cast it to double.
}
double max = sum; //initialize a variable that has that value which you will maximize
for ( int i = x; i < n; i++ ) {
sum = (double)( arr[ix] ) / x; //leave the first in the x elements
sum += (double)( arr[i] ) / x; // add the current element so you always compute average of `x` elements.
max = Math.max( max, sum ); //maximize max
}
return max;

