Longest Non Decreasing Subarray Part 2
Updated
Problem statement
Note 📝 - This is a follow up question of Find Maximum Length of Non-Decreasing Subarray Part 1 🦭
You can choose any one index and change its value to any number that you like. What will be the longest non decreasing subarray now:
In the same example as before, the answer would now be:
ans = 6, [2 4 6 8 0 9], by changing 0 -> 8 so the subarray becomes non-decreasing.
Function
longestNonDecreasingSubarray(nums: int[]) → intExamples
Example 1
nums = [2, 4, 6, 8, 0, 9]return = 6By changing the value at index 4 from 0 to 8, the array becomes [2, 4, 6, 8, 8, 9], which is non-decreasing. The length of this subarray is 6, which is the longest possible non-decreasing subarray after making one change.
Constraints
1 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9- You may change at most one element to any integer value.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
- Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Jump GamePaytm · PHONE SCREENPaytm interview questions
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- House RobberVisa · PHONE SCREENVisa interview questions
- Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
- Longest Increasing SubsequenceAngel One · PHONE SCREEN
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN