Problem 54. Maximum running product for a string of numbers
Given a string s representing a list of numbers, find the five consecutive numbers that multiply to form the largest number. Specifically, given s return the index i to the first of those five numbers. You can assume the maximum product is unique.
Example:
Input s = '123454321' Output i = 3
since the product of [3 4 5 4 3] is larger than any of the alternatives.
Inspired by Problem 8 from Project Euler
Solution Stats
Problem Comments
-
2 Comments
It's a pity the test set does not include a case such that the largest running sum is not also the largest running product. Some solutions, including my solution of size 23, should fail because they take the sum, not the product.
I would suggest adding '9909911111' as a test case. That would weed out all people who took a shortcut by using a moving sum, instead of a moving product.
Solution Comments
Show commentsProblem Recent Solvers2161
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5637 Solvers
-
Project Euler: Problem 3, Largest prime factor
1431 Solvers
-
Cell Counting: How Many Draws?
1901 Solvers
-
The Answer to Life, the Universe, and Everything
528 Solvers
-
Calculate Amount of Cake Frosting
24958 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!