Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Cisco interview question

Largest sum of a non-empty contiguous subarray

Company:
Cisco
Type:
Coding
Difficulty:
Medium
Reported:
October 19, 2026

Problem

Given an integer array nums, find the contiguous subarray with at least one element that has the largest sum, and return that sum.

Example 1

Input: nums = [2, -5, 3, -1, 4, -2]
Output: 6

[3, -1, 4] sums to 6. Extending it to the left adds 2 - 5 = -3, and extending it to the right adds -2, so neither helps.

Example 2

Input: nums = [-4, -2, -7]
Output: -2

Every element is negative, so the best subarray is the single largest element.

Constraints

  • 1 <= len(nums) <= 10^5
  • -10^4 <= nums[i] <= 10^4

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern