Maximum Product Subarray Java Coding Challenge | Leetcode | How'd You Code That?

Published: 28 September 2020
on channel: Ed Clark
237
8

Maximum Product Subarray on Leetcode:
https://leetcode.com/problems/maximum...

The maximum subarray problem is the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array of numbers:

[−2, 1, −3, 4, −1, 2, 1, −5, 4], the contiguous subarray with the largest sum is [4, −1, 2, 1], with sum 6.

Professor Ulf Grenander was a Swedish statistician and professor of applied mathematics at Brown University. His early research was in probability theory, stochastic processes, time series analysis, and statistical theory.

In 1977, Professor Grenander encountered a problem in pattern recognition where he needed to find the maximum sum over all rectangular regions of a given min array of real numbers. This rectangular region of the maximum sum, or maximum subarray, was to be used as the maximum likelihood estimator of a certain kind of pattern in a digitized picture.

Maximum subarray problems arise in many fields, including genetic sequence analysis, computer vision and data mining.

We are solving The Maximum Subarray HackerRank Challenge.
The problem statement reads:

We define subsequence as any subset of an array. We define a subarray as a contiguous subsequence in an array.
Given an array, find the maximum possible sum among:
1. all nonempty subarrays.
2. all nonempty subsequences.
Print the two values as space-separated integers on one line.
Note that empty subarrays/subsequences should not be considered.

For example, given an array, consisting of -1, 2, 3, -4, 5 and 10, the maximum subarray sum is comprised of elements at indices one through 5, and the sum is 2+3+-4+5+10 for a total of 16. The maximum subsequence sum is comprised of the elements at indices, 1,2,4 and 5, and the sum is 2+3+5+10, for a total of 20.

Genomic sequence analysis employs maximum subarray algorithms to identify important biological segments of protein sequences. Given that, a computer-based sequence analysis is becoming increasingly popular. Computerized algorithms designed for structure prediction of a protein sequence can be an invaluable tool for biologists to quickly understand the protein’s function, which is the first step towards the development of antibodies, drugs.

In computer vision, maximum-subarray algorithms are used on bitmap images to detect the brightest area in an image:

It can also detect the warmest regions in a thermo-graphic image.

One data mining application where the maximum subarray is invaluable is determining for a given range of customers, whose ages are 10i ≤ age
10(i + 1), are likely to purchase product ‘x’.

which is normalized by subtracting the mean 1/2, such that:

The array portion a[2..3] is the maximum subarray, which suggests that customers in their twenties and thirties are promising groups for purchasing product ‘x’.

After hearing of the Maximum Subarray problem at a Carnegie Mellon University seminar, Professor Joseph Born Kadane quickly designed a linear time algorithm to solve it

Kadane’s algorithm scans the given array from left to right. In each step, it computes the subarray with the largest sum. It also computes the subarray with the largest sum anywhere between the first and the current index.
As of today, Kadane's algorithm remains the fastest method for solving the Maximum Subarray problem.

Closed Captions/Subtitles - [email protected]

Video Editing - [email protected]

Song: Stardust - Fresh (Vlog No Copyright Music)
Music promoted by Vlog No Copyright Music.
  / ikson  


Watch video Maximum Product Subarray Java Coding Challenge | Leetcode | How'd You Code That? online without registration, duration hours minute second in high quality. This video was added by user Ed Clark 28 September 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 237 once and liked it 8 people.