Jobs
Interviews

Solve Longest Subarray with Difference One using Lua Language

Solve Longest Subarray with Difference One using Lua to enhance your skills with lua coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Longest Subarray with Difference One

Difficulty : Medium

Categories :

  • Arrays

Given an array of integers, find the length of the longest subarray where the absolute difference between any two elements is at most 1. A subarray is a contiguous portion of the array.

Constraints:

  • 1 ≤ arr.length ≤ 10⁵
  • 0 ≤ arr[i] ≤ 10⁴
  • Answer will fit in a 32-bit integer

Examples:

Input: [1,3,2,2,5,2,3,7]
Output: 5
Explanation: Longest subarray is [3,2,2,2,3] with length 5
Input: [1,1,1,1]
Output: 4
Explanation: Entire array is valid

Problem Solving

Input

What You'll Find Here

Real-World Applications Solve problems inspired by Lua's common use cases, such as game development and embedded systems.

Step-by-Step Guidance Break down Lua's concepts into digestible lessons.

Practical Skills Build hands-on experience with Lua for real-world projects.

Choose from the following categories