Question 956 – Nielit Scientist-B IT 4-12-2016
December 3, 2023Question 1185 – Nielit Scientist-B CS 22-07-2017
December 3, 2023Question 1186 – Nielit Scientist-B CS 22-07-2017
Kadane algorithm is used to find
Correct Answer: B
Question 39 Explanation:
Kadane algorithm is used to find the maximum sum subarray in an array. It runs in O(n) time complexity
Implementation in python:
def max_subarray(A):
max_ending_here = max_so_far = A[0]
for x in A[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
Implementation in python:
def max_subarray(A):
max_ending_here = max_so_far = A[0]
for x in A[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
Maximum sum subsequence in an array
Maximum sum subarray in an array
Maximum product subsequence in an array
Maximum product subarray in an array
Subscribe
Login
0 Comments