PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Maximize sum with no adjacent elements

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of dynamic programming and array-based optimization, assessing competency in designing algorithms that maximize a sum under adjacency constraints.

  • medium
  • TikTok
  • Coding & Algorithms
  • Machine Learning Engineer

Maximize sum with no adjacent elements

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an array of non-negative integers `nums`, choose a subset of elements such that **no two chosen elements are adjacent in the original array**. Return the **maximum possible sum** of the chosen elements. ### Input - `nums`: array of integers, `0 <= nums[i]` ### Output - An integer: the maximum sum achievable without choosing adjacent elements. ### Constraints (typical interview constraints) - `1 <= n <= 10^5` - `0 <= nums[i] <= 10^9` ### Examples - `nums = [1,2,3,1]` → `4` (choose `1` and `3`) - `nums = [2,7,9,3,1]` → `12` (choose `2, 9, 1`)

Quick Answer: This question evaluates understanding of dynamic programming and array-based optimization, assessing competency in designing algorithms that maximize a sum under adjacency constraints.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Feb 12, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
7
0

Given an array of non-negative integers nums, choose a subset of elements such that no two chosen elements are adjacent in the original array.

Return the maximum possible sum of the chosen elements.

Input

  • nums : array of integers, 0 <= nums[i]

Output

  • An integer: the maximum sum achievable without choosing adjacent elements.

Constraints (typical interview constraints)

  • 1 <= n <= 10^5
  • 0 <= nums[i] <= 10^9

Examples

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

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Machine Learning Engineer•TikTok Machine Learning Engineer•TikTok Coding & Algorithms•Machine Learning 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.