2148. Count Elements With Strictly Smaller and Greater Elements ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9class Solution { public: int countElements(vector<int>& nums) { const int mn = ranges::min(nums); const int mx = ranges::max(nums); return ranges::count_if( nums, [&](const int num) { return mn < num && num < mx; }); } }; 1 2 3 4 5 6 7class Solution { public int countElements(int[] nums) { final int mn = Arrays.stream(nums).min().getAsInt(); final int mx = Arrays.stream(nums).max().getAsInt(); return (int) Arrays.stream(nums).filter(num -> mn < num && num < mx).count(); } } 1 2 3 4 5class Solution: def countElements(self, nums: list[int]) -> int: mn = min(nums) mx = max(nums) return sum(mn < num < mx for num in nums)