FastPrepCount Bowl Subarrays
Problems/Count Bowl Subarrays

Count Bowl Subarrays

PhonePe logoPhonePe● MediumONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real PhonePe onsite interview report. The report linked the exact Count Bowl Subarrays task, but it did not reproduce the rules, function interface, examples, or constraints. The core task match is about 95%.

You are given an integer array nums with distinct elements.

A subarray nums[l...r] is a bowl when:

  • Its length is at least 3.
  • The smaller of its two endpoint values is strictly greater than every value between the endpoints.

Return the number of bowl subarrays.

Function

bowlSubarrays(nums: int[]) → long

Examples

Example 1

nums = [2,5,3,1,4]return = 2

The bowl subarrays are [3,1,4] and [5,3,1,4].

Example 2

nums = [5,1,2,3,4]return = 3

The valid bowl subarrays are [5,1,2], [5,1,2,3], and [5,1,2,3,4].

Constraints

  • 3 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9
  • nums contains distinct values.

More PhonePe problems

  • Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
  • K-th Smallest Value in a Sorted MatrixONSITE INTERVIEW · Seen Oct 2026
  • Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
All PhonePe interview questionsSee PhonePe hiring insights
Saved
class Solution {
    public long bowlSubarrays(int[] nums) {
      // write your code here
    }
}
Checking account…