Maximum Absolute Difference
You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as |A[i] - A[j]| + |i - j|, where |x| denotes absolute value of x.For example,A=[1, 3, -1] f(1, 1) = f(2, 2) = f(3, 3) = 0 f(1, 2) = f(2, 1) = |1 - 3| + |1 - 2| = 3 f(1, 3) = f(3, 1) = |1 - (-1)| + |1 - 3| = 4 f(2, 3) = f(3, 2) = |3 - (-1)| + |2 - 3| = 5 So, we return 5. ..
더보기
Max Sum Contiguous Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example:Given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the largest sum = 6.For this problem, return the maximum sum. My Solutions:import sys def maxSubArray(A): size = len(A) max_sum = max(A[0], -sys.maxsize - 1) for i in range(size): result = A[i] for j in ..
더보기
CHOOSE2
Which of the given options provides the increasing order of complexity of functions f1, f2, f3 and f4:f1(n) = 2^n f2(n) = n^(3/2) f3(n) = nLogn f4(n) = n^(Logn) f3, f2, f4, f1 f3, f2, f1, f4 f2, f3, f1, f4 f2, f3, f4, f1Good solution:n < nlog(n)n^x < n^y if x < yn^x < c^n where c is a constant (polynomials will eventually grow slower than exponentials)log(n) < nc^n < n! < n^n where c is a constant
더보기