FastPrepCount Subarrays with Bitwise OR Present
Problems/Count Subarrays with Bitwise OR Present

Count Subarrays with Bitwise OR Present

Microsoft logoMicrosoft● HardOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Given an array of size up to 100000, count the number of subarrays for which the bitwise OR of all the elements of the subarray is present in that subarray itself. We need an efficient solution with O(n) or O(nlogn) time complexity.

Function

countSubarraysWithBitwiseORPresent(arr: int[]) → long

Examples

Example 1

arr = [1, 6, 7]return = 5

🦇

Example 2

arr = [2, 4, 7]return = 5

🦕

Constraints

  • 1 <= arr.length <= 100,000
  • Each element fits in a signed 32-bit integer.

More Microsoft interview questions

  • Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
  • Authentication SystemOA · Seen Nov 2026
  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximize K-Element AND with an Increment BudgetAmazon · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Minimum Cost to Reach a Target WeightChubb · OAChubb interview questions
  • Distinct OR Values of Increasing SubsequencesScale AI · OAScale AI interview questions
  • Maximum XOR for Each QueryUber · OAUber interview questions
  • Minimum Inversions 🍑TikTok · OATikTok interview questions
  • Maximum XOR Elimination ScoreRippling · OARippling interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long countSubarraysWithBitwiseORPresent(int[] arr) {
      // write your code here
    }

}
Checking account…