Beautiful Subarrays
Updated
Problem statement
A beautiful subarray contains exactly k odd elements.
Given an integer array nums and a non-negative integer k, return the number of distinct beautiful subarrays. Subarrays are distinct by their inclusive start and end indices.
Function
beautifulSubarrays(nums: int[], k: int) → longExamples
Example 1
nums = [1,2,3,4,5]k = 2return = 4The four beautiful subarrays are [1,2,3], [1,2,3,4], [2,3,4,5], and [3,4,5].
Example 2
nums = [2,5,4,9]k = 2return = 2The beautiful subarrays are [5,4,9] and the complete array.
Constraints
1 <= nums.length <= 200000-10^9 <= nums[i] <= 10^90 <= k <= nums.length- The answer fits a signed
long.
More Atlassian Online Assessment questions
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Count Zero-Sum FragmentsTesla · OATesla interview questions
- Count Stable Server SubsegmentsScale AI · OAScale AI interview questions
- Number of Unique Elements After Modifications 🍁Infosys · OAInfosys interview questions
- Count Paired Subarrays Reaching a TargetZipRecruiter · OAZipRecruiter interview questions
- Count Subarrays with Sum KIndeed · OAIndeed interview questions
- Count Subarrays With Given XORInMobi · OAInMobi interview questions
- Count Subarrays with Sum Divisible by KVisa · OAVisa interview questions
- Find Security LevelAmazon · OA
- Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions