
Asked in Visa
Find Maximum Length Sub-array with Specific Adjacent Differences
Given an array of integers ‘A’ of length ‘N’, find the maximum length of a sub-array where the absolute difference between adjacent elements is either 0 or 1.
Example:
Input:
A = [2, 4, 6, 7, 6, 9]
Output:
3
Explanation:
The sub-array [6, 7, 6] has adjacent elements with absolute differences of either 0 or 1, and its length is 3, which is the maximum possible.
Input:
T = number of test cases
For each test case:
N = number of elements in the array
Array A with N space-separated integers
Output:
For each test case, output the maximum length of the sub-array as a single integer in a new line.
Constraints:
- 1 <= T <= 50
- 1 <= N <= 104
- -108 <= A[i] <= 108
Time limit: 1 sec.
Note:
No need to print the output; it is handled automatically. Implement the function to output the results.

AnswerBot
4mo
Find the maximum length of a sub-array with adjacent differences of 0 or 1 in an array of integers.
Iterate through the array and keep track of the current sub-array length with adjacent differences of...read more
Omprakash Ray
5mo
int tempSum = 0; int sum = 0; int[] arr = {2, 4, 6, 7, 6, 9, 5, 4, 3, 2}; for(int i = 0; i< arr.length-1; i++) { if(Math.abs(arr[i+1]-arr[i]) == 0 || Math.abs(arr[i+1]-arr[i]) == 1) { tempSum = tempSu...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Visa
Q. How would you design Google Pay?
Q. HLD of recursive
Q. Why did you only pass 10 out of 14 test cases in the 4th question?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Visa Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

