PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Maximize sum without choosing adjacent elements

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of array-based optimization and dynamic programming concepts for computing a maximum sum under non-adjacent selection constraints.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Maximize sum without choosing adjacent elements

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an integer array `nums` where `nums[i]` is the value in position `i`. Select a subset of indices such that **no two selected indices are adjacent** (i.e., you cannot select both `i` and `i+1`). Return the **maximum possible sum** of the selected values. ### Input - `nums`: array of integers (can include `0`) ### Output - An integer: the maximum achievable sum under the non-adjacent constraint. ### Constraints (reasonable interview assumptions) - `1 <= nums.length <= 2 * 10^5` - `0 <= nums[i] <= 10^9` - Time target: `O(n)` - Space target: `O(1)` or `O(n)` ### Examples - `nums = [2, 7, 9, 3, 1]` → `12` (pick `2 + 9 + 1`) - `nums = [1, 2, 3, 1]` → `4` (pick `1 + 3`)

Quick Answer: This question evaluates a candidate's understanding of array-based optimization and dynamic programming concepts for computing a maximum sum under non-adjacent selection constraints.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

Problem

You are given an integer array nums where nums[i] is the value in position i.

Select a subset of indices such that no two selected indices are adjacent (i.e., you cannot select both i and i+1). Return the maximum possible sum of the selected values.

Input

  • nums : array of integers (can include 0 )

Output

  • An integer: the maximum achievable sum under the non-adjacent constraint.

Constraints (reasonable interview assumptions)

  • 1 <= nums.length <= 2 * 10^5
  • 0 <= nums[i] <= 10^9
  • Time target: O(n)
  • Space target: O(1) or O(n)

Examples

  • nums = [2, 7, 9, 3, 1] → 12 (pick 2 + 9 + 1 )
  • nums = [1, 2, 3, 1] → 4 (pick 1 + 3 )

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.