1. Engineering
  2. Computer Science
  3. write a python function randarrayn x that takes two positive...

Question: write a python function randarrayn x that takes two positive...

Question details

write a Python function rand_array(n, x) that takes two positive integers, n and x, and returns an array of length n each of whose elements is a random integer in the range -x,...,x.

Write a function max_sum(a) that takes an array, a, of numbers and returns a pair of indices (i,j) such that the sum a[i]+a[i+1]+a[i+2]+...+a[j-1] is as large as possible.

For example, if a=[-1, -2, 3, 5, 2, -3, 1, 1], the max_sum(a) would return (2,5) since

a[2]+a[3]+a[4]=3+5+2=10

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution