Count of Elements Less Than Target
You are given a list of integers arranged in ascending order and a target value. Your task is to determine how many numbers in the list are strictly smaller than the target. The answer you return is a single integer that represents a count, not a position.
Think of the list as a sorted line of values on a number line. Starting from the left, every element that sits below the target should be included in the tally, while any element that equals or exceeds the target is excluded. If the list is empty, there are no qualifying values, so the result is 0. If the target is less than or equal to the first element, the result is also 0. If the target is larger than all elements, the result equals the length of the list.
Be mindful that the list may contain duplicates, and those duplicates should be counted if they are strictly less than the target. The order of elements is already given as ascending, so you do not need to rearrange or modify the data. Your job is to derive the correct count in a way that respects the ordered nature of the values and the strictness of the comparison. Return an integer that accurately summarizes how many elements come before the target in value.
Example 1:
Input: nums = [1, 2, 4, 4, 7], target = 4
Output: 2
Explanation: Only 1 and 2 are strictly less than 4, so the count is 2.
Example 2:
Input: nums = [3, 3, 3], target = 3
Output: 0
Explanation: No element is strictly smaller than 3.
Example 3:
Input: nums = [], target = 10
Output: 0
Explanation: The list is empty, so the count is 0.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
