Mastercard Off Campus OA 2022 | Dynamic Programming Optimization for Handling Negative Values and Maximum Contiguous Product Computation

Mastercard · Question · Posted Jun 2026

Problem Statement Given an integer array nums, find the contiguous non-empty subarray within the array that has the largest product and return that product. The array may contain: Positive integers Negative integers Zeroes A negative number can turn a small negative product into a large positive product, making this problem more challenging than the classic Maximum Subarray Sum problem. Example 1 Input: nums = [2,3,-2,4] Output: 6 Explanation: Subarray [2,3] has product = 6 Example 2 Input: nums = [-2,0,-1] ...

The full answer & interview discussion are available to premium members.

Log in Create a free account