LeetCode solutions

2269. Count Elements With Strictly Smaller and Greater Elements

My accepted Python solution to LeetCode problem 2269, Count Elements With Strictly Smaller and Greater Elements, running in 2ms.

  • Difficulty: Easy
  • Python
  • Runtime 2ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 2ms, memory 17.2MB, accepted 2025-12-30.

python
class Solution:
    def countElements(self, nums: List[int]) -> int:
        if len(nums) < 3:
            return 0
        min_val = min(nums)
        max_val = max(nums)
        return sum(1 for num in nums if min_val < num < max_val)

Source