Jobs
Interviews

Solve Count Limited Range Subsequences using C Language

Solve Count Limited Range Subsequences using C to enhance your skills with c coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Count Limited Range Subsequences

Difficulty : Hard

Categories :

  • Arrays

You are given an array of integers arr and an integer k. Your task is to find the number of subsequences in the array where:

  • The subsequence length is exactly k
  • The difference between the maximum and minimum elements in the subsequence is at most 2

Return the count of such subsequences.

Constraints:

  • 1 ≤ k ≤ arr.length ≤ 1000
  • 1 ≤ arr[i] ≤ 100
  • The answer will be less than 2^31

Examples:

Input: arr = [3,1,4,1,5], k = 2
Output: 3
Explanation: Valid subsequences are: [1,1], [3,4], [4,5]
Note that [1,5] is not valid as 5-1 > 2
Input: arr = [1,1,1,2,2], k = 2
Output: 10
Explanation: All possible subsequences of length 2 are valid as max difference is at most 1

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