Count Subarrays With Max Element Constraint

Given an integer array nums and an integer k, return the number of subarrays where the maximum element in the subarray is equal to k.

Examples
Input: [[1,3,2,1,4,5],3]
Output: 9
Hints

Count Subarrays With Max Element Constraint

Given an integer array `nums` and an integer `k`, return the number of subarrays where the maximum element in the subarray is equal to `k`.