LENSKART Hiring| SDE OA (2024) | Counting Valid Subarrays Within a Maximum Value Range
Question · Posted Jun 2026
Problem Statement Given an integer array nums and two integers left and right, return the number of contiguous subarrays where the maximum element lies within the inclusive range [left, right]. A subarray is considered valid if: left <= max(subarray) <= right Your task is to count all such valid subarrays efficiently. Example 1 Input: nums = [2,1,4,3] left = 2 right = 3 Output: 3 Explanation Valid subarrays: [2] [2,1] [3] Total valid subarrays = 3 Example 2 Constraints 1 ...
The full answer & interview discussion are available to premium members.
Log in Create a free account