PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/TikTok

Maximize min+max of contiguous subarray

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of array algorithms and competency in identifying and reasoning about minimum and maximum values within contiguous subarrays, emphasizing extremal value handling.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Maximize min+max of contiguous subarray

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an array of **n** positive integers `nums`. Find a **contiguous subarray** that contains **at least two elements** and maximizes the value: > (minimum element of the subarray) + (maximum element of the subarray) Return this maximum possible sum. If multiple subarrays yield the same maximum sum, you only need to return the value of that sum (not the subarray itself). You may assume `n ≥ 2`. --- **Example** Input: ```text nums = [5, 12, 9, 6, 4] ``` All valid subarrays of length ≥ 2 and their `(min + max)` values include: - `[5, 12]` → min = 5, max = 12, sum = 17 - `[5, 12, 9]` → min = 5, max = 12, sum = 17 - `[12, 9]` → min = 9, max = 12, sum = 21 - `[12, 9, 6]` → min = 6, max = 12, sum = 18 - `[9, 6]` → min = 6, max = 9, sum = 15 - ... The maximum possible value of `min + max` is `21`, from subarray `[12, 9]`. **Output:** ```text 21 ```

Quick Answer: This question evaluates understanding of array algorithms and competency in identifying and reasoning about minimum and maximum values within contiguous subarrays, emphasizing extremal value handling.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Oct 11, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

You are given an array of n positive integers nums.

Find a contiguous subarray that contains at least two elements and maximizes the value:

(minimum element of the subarray) + (maximum element of the subarray)

Return this maximum possible sum.

If multiple subarrays yield the same maximum sum, you only need to return the value of that sum (not the subarray itself).

You may assume n ≥ 2.

Example

Input:

nums = [5, 12, 9, 6, 4]

All valid subarrays of length ≥ 2 and their (min + max) values include:

  • [5, 12] → min = 5, max = 12, sum = 17
  • [5, 12, 9] → min = 5, max = 12, sum = 17
  • [12, 9] → min = 9, max = 12, sum = 21
  • [12, 9, 6] → min = 6, max = 12, sum = 18
  • [9, 6] → min = 6, max = 9, sum = 15
  • ...

The maximum possible value of min + max is 21, from subarray [12, 9].

Output:

21

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 7,500+ 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.