Count Bowl Subarrays
Updated
Problem statement
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[]) → longExamples
Example 1
nums = [2,5,3,1,4]return = 2The bowl subarrays are [3,1,4] and [5,3,1,4].
Example 2
nums = [5,1,2,3,4]return = 3The valid bowl subarrays are [5,1,2], [5,1,2,3], and [5,1,2,3,4].
Constraints
3 <= nums.length <= 10^51 <= nums[i] <= 10^9numscontains distinct values.
More PhonePe interview questions
- Maximum Sum with K-Element SkippingONSITE INTERVIEW · Seen Dec 2026
- Minimum Number of Days to Make m BouquetsONSITE INTERVIEW · Seen Dec 2026
- 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
- Reconstruct ItineraryONSITE INTERVIEW · Seen Jul 2026
- Constrained Jump SequencesOA · Seen Aug 2026
- Maximum Payout with Context SwitchesOA · Seen Aug 2026
- Substrings Without a Target SubsequenceOA · Seen Aug 2026
- Luna and the Colorful SocksOA · Seen Jul 2026
Similar questions at other companies
- Generic Stack Operation SequenceArista Networks · PHONE SCREEN · ONSITE INTERVIEWArista Networks interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Next Smaller Ticket PriceAmazon · ONSITE INTERVIEW
- Next Greater Element to the RightTekion · ONSITE INTERVIEWTekion interview questions
- Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Daily TemperatureseBay · ONSITE INTERVIEWeBay interview questions
- Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions