FastPrepLongest Alternating Subarray After One Deletion

Longest Alternating Subarray After One Deletion

Google logoGoogle● HardINTERNONSITE INTERVIEW

Problem statement

You are given an integer array nums. Choose a contiguous segment of the original array, then delete at most one element from that segment. The remaining elements keep their original order.

The remaining sequence is alternating when every adjacent comparison is strict and its direction alternates: greater, less, greater, less, or less, greater, less, greater. Equal adjacent elements break alternation. A sequence of length 0 or 1 is alternating.

The problem statement continues
Pro

Examples

Example 1

nums = [1,3,2,2,4,1]return = 5

Delete one of the adjacent 2s. The entire segment becomes [1,3,2,4,1], whose comparisons alternate.

FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week