Skip to content
Onsite

Count Elements at Odd Positions Below K

EasyP3Coding

Count the elements of nums that are at odd indices (1, 3, 5, ...) and are strictly less than k. Indices start at 0.

Example 1

Input
nums = [5,1,9,2,3], k = 4
Output
2
Why
Odd indices hold 1 and 2; both are less than 4.

Example 2

Input
nums = [1], k = 5
Output
0

Example 3

Input
nums = [], k = 5
Output
0

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i], k <= 10^9

Hints

Run checks the 3 visible tests, Submit all 10.