Increasing Subsegment Problem Statement

Given a sequence ARR consisting of N integers, your task is to identify the longest subsegment of ARR, where you can change at most one number to make the subsegment strictly increasing.

Input:

The first line contains a single integer T representing the number of test cases.
Each test case starts with an integer 'N' (length of 'ARR').
The second line of each test case follows with 'N' space-separated integers denoting the elements of 'ARR'.

Output:

For each test case, output the length of the longest possible subsegment after changing at most one number.

Example:

Input:
2
4
1 3 2 4
5
10 20 10 30 40
Output:
4
5

Constraints:

  • 1 <= T <= 10
  • 1 ≤ N ≤ 105
  • 1 ≤  ARR[i]  ≤ 109
  • Time Limit: 1 sec

Note:

You do not need to print anything, it has already been taken care of. Just implement the given function.

AnswerBot
2d

Find the longest subsegment where at most one number can be changed to make it strictly increasing.

  • Iterate through the array and keep track of the longest increasing subsegment with at most one change...read more

Help your peers!
Add answer anonymously...
ACKO Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter