Jobs
Interviews

Solve Longest Smooth Subarray using C Language

Solve Longest Smooth Subarray using C to enhance your skills with c coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Longest Smooth Subarray

Difficulty : Hard

Categories :

  • Arrays

Given an array of integers arr and an integer k, a smooth subarray is defined as a subarray where the difference between any two adjacent elements is at most k. Find the length of the longest smooth subarray.

A subarray is a contiguous part of an array.

Constraints:

  • 1 ≤ arr.length ≤ 10^5
  • -10^9 ≤ arr[i] ≤ 10^9
  • 0 ≤ k ≤ 10^9

Examples:

Input: arr = [5,4,2,4,3,3,6], k = 2
Output: 4
Explanation: The subarray [4,2,4,3] is smooth as adjacent differences are: 2,2,1
All differences are ≤ k=2
Input: arr = [1,5,3,2,6], k = 1
Output: 2
Explanation: No subarray longer than 2 has all adjacent differences ≤ 1

Coding works best on a laptop or desktop, with a keyboard and a wider editor. You can read the problem here and solve it there.

Problem Solving

Input

What You'll Find Here

Practical Challenges Solve coding problems that strengthen your understanding of C.

Step-by-Step Tutorials Learn how to write efficient and optimized code.

Career-Focused Skills Prepare for technical interviews with targeted exercises.

Choose from the following categories