Post, Code and Quiet Time.
  • Home
Sign in Subscribe

Subarray

A collection of 3 posts
dynamic programming

Maximum Subarray III

Question: http://www.lintcode.com/en/problem/maximum-subarray-iii/ Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum. Answer localMax[i][j], means the maximum sum we can get while
Nov 22, 2017 1 min read
Forward-Backward Traversal,

Maximum Subarray II

Question: Given an array of integers, find two non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum. Notice The subarray should contain at least one number Answer: class Solution { public: /* * @param nums: A list of integers * @return: An integer denotes
Nov 22, 2017 1 min read
Greedy

Maximum Subarray

Question: http://www.lintcode.com/en/problem/maximum-subarray/ Given an array of integers, find a contiguous subarray which has the largest sum. Time Complexity: O(n) Answer: void maxsumofsubarray(int* array, int len) { int curMax = 0; int mi = -1; int mj = -1; int max; bool max_init = false; for (int
Oct 20, 2017
Page 1 of 1
Post, Code and Quiet Time. © 2023
Powered by Ghost