Population Alive in a Target Year
Updated
Problem statement
The parallel arrays birthYears and deathYears describe a population. Person i is alive in every integer year from birthYears[i] through deathYears[i], inclusive.
Given an integer year, return how many people are alive during that year. Return 0 when the population is empty.
Function
countPopulationInYear(birthYears: int[], deathYears: int[], year: int) → intExamples
Example 1
birthYears = [1900,1920,1930]deathYears = [1950,1940,1970]year = 1935return = 3All three people were born by 1935 and none had died before 1935.
Example 2
birthYears = [2000,1990,2010]deathYears = [2000,1999,2015]year = 2000return = 1The first person counts in both the birth and death year. The second died before 2000, and the third was born later.
Example 3
birthYears = []deathYears = []year = 2025return = 0An empty population has nobody alive in any year.
Constraints
0 <= birthYears.length = deathYears.length <= 100000.0 <= birthYears[i] <= deathYears[i] <= 1000000000.0 <= year <= 1000000000.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
- Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Minimum Operations to Make an Array ContinuousAmazon · ONSITE INTERVIEW
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Room Occupancy at Query TimesWhatNot · ONSITE INTERVIEWWhatNot interview questions
- Count Later Lower ReadingsRippling · ONSITE INTERVIEWRippling interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Smallest Common Integer in Sorted ListsMotive · ONSITE INTERVIEWMotive interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)