PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Find longest increasing contiguous subarray

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in array processing and algorithmic optimization, focusing on recognition of contiguous subarray properties and handling a single-value modification to achieve strict monotonicity.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find longest increasing contiguous subarray

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an integer array `nums` (length `n`). ### Part 1 Find the length of the **longest contiguous subarray** that is **strictly increasing** (i.e., for every adjacent pair in the subarray, `a[i] < a[i+1]`). **Input:** `nums: int[]` **Output:** `maxLen: int` **Example:** - `nums = [1, 2, 2, 3, 4]` → longest strictly increasing contiguous subarray is `[2,3,4]`, so `maxLen = 3`. ### Follow-up Now suppose you may **modify (replace) the value of at most one element** within a chosen contiguous subarray (replace it with any integer value you want) in order to make that subarray strictly increasing. Return the maximum possible length of a contiguous subarray that can be made strictly increasing with **≤ 1** replacement. **Clarification/assumption (make explicit in interview):** The replacement value is unconstrained (can be any integer), and you are asked only for the maximum achievable length. **Example idea:** - `nums = [1, 5, 3, 4]` → by replacing `5` with `2`, the whole array can become `[1,2,3,4]`, so answer is `4`. ### Constraints (reasonable interview defaults) - `1 <= n <= 2e5` - `-1e9 <= nums[i] <= 1e9` - Aim for better than `O(n^2)` in the follow-up.

Quick Answer: This question evaluates proficiency in array processing and algorithmic optimization, focusing on recognition of contiguous subarray properties and handling a single-value modification to achieve strict monotonicity.

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
11
0
Loading...

Problem

You are given an integer array nums (length n).

Part 1

Find the length of the longest contiguous subarray that is strictly increasing (i.e., for every adjacent pair in the subarray, a[i] < a[i+1]).

Input: nums: int[]

Output: maxLen: int

Example:

  • nums = [1, 2, 2, 3, 4] → longest strictly increasing contiguous subarray is [2,3,4] , so maxLen = 3 .

Follow-up

Now suppose you may modify (replace) the value of at most one element within a chosen contiguous subarray (replace it with any integer value you want) in order to make that subarray strictly increasing.

Return the maximum possible length of a contiguous subarray that can be made strictly increasing with ≤ 1 replacement.

Clarification/assumption (make explicit in interview): The replacement value is unconstrained (can be any integer), and you are asked only for the maximum achievable length.

Example idea:

  • nums = [1, 5, 3, 4] → by replacing 5 with 2 , the whole array can become [1,2,3,4] , so answer is 4 .

Constraints (reasonable interview defaults)

  • 1 <= n <= 2e5
  • -1e9 <= nums[i] <= 1e9
  • Aim for better than O(n^2) in the follow-up.

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.