Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Count Subarrays by Divisor Sum
00:00
5 left

Count Subarrays by Divisor Sum

HardPython

Problem

Given an array, count the number of subarrays whose sum of divisor counts of elements is odd.

Asked in the Online assessment stage. Coding round, 3 questions in 1h30.

Implement count_odd_divisor_sum_subarrays(nums). The input is an array of positive integers. For each element, determine its number of positive divisors. Return the number of contiguous subarrays whose divisor counts sum to an odd number.

Examples

  • nums = [1, 2, 4] returns 4. Their divisor-count parities are [1, 0, 1].
  • nums = [2, 3, 5] returns 0, because every element has an even number of divisors.

Constraints

  • 1 <= nums.length <= 100000
  • 1 <= nums[i] <= 1000000000

Constraints

  • 1 <= nums.length <= 100000
  • 1 <= nums[i] <= 1000000000
  • The result fits in a signed 64-bit integer

Function Signature

def count_odd_divisor_sum_subarrays(nums):
Interviewer

Your question is Count Subarrays by Divisor Sum. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.