FastPrepBeautiful Subarrays
Problems/Beautiful Subarrays

Beautiful Subarrays

Atlassian logoAtlassian● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Atlassian new grad online assessment. The report shows the whole problem. Our version is about 99% the same as the reported question.

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) → long

Examples

Example 1

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

The 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 = 2

The beautiful subarrays are [5,4,9] and the complete array.

Constraints

  • 1 <= nums.length <= 200000
  • -10^9 <= nums[i] <= 10^9
  • 0 <= 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

Atlassian interview experiences

  • Atlassian MLE Phone Screen: Model Deployment Design: 1 Experience
  • Atlassian Coding Screens and Karat: 3 Experiences (Part 2 of 2)
  • Atlassian Full Stack Interviews: 11 Experiences (Part 1 of 2)
All Atlassian interview questionsSee Atlassian hiring insights
Saved
class Solution {
    public long beautifulSubarrays(int[] nums, int k) {
      // Write your code here.
    }

}
Checking account…