FastPrepSelect a City by Population Weight
Problems/Select a City by Population Weight

Select a City by Population Weight

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta phone screen. The original report asks to pick a city with a chance in proportion to its population. It leaves out the random draw and the rules at the boundaries. Our version is about 85% the same as the reported question.

You are given parallel arrays cities and populations. Each positive population is the selection weight of the city at the same index.

You are also given a zero-based integer ticket in the range from 0 through the total population minus one. Assign consecutive ticket ranges to cities in input order, with each range length equal to that city's population.

Return the city whose range contains ticket. If a ticket is chosen uniformly from the valid range, this mapping selects every city with probability proportional to its population.

Function

selectCityByPopulation(cities: String[], populations: int[], ticket: int) → String

Examples

Example 1

cities = ["Alpha","Beta","Gamma"]populations = [2,3,5]ticket = 0return = "Alpha"

Alpha owns tickets 0 and 1.

Example 2

cities = ["Alpha","Beta","Gamma"]populations = [2,3,5]ticket = 4return = "Beta"

Beta owns tickets 2, 3, and 4.

Example 3

cities = ["North","South"]populations = [1,9]ticket = 9return = "South"

South owns tickets 1 through 9, including the final valid ticket.

Constraints

  • 1 <= cities.length = populations.length <= 100000.
  • Every city name is nonempty, and city names are distinct.
  • 1 <= populations[i].
  • The total population is at most 2,000,000,000.
  • 0 <= ticket < sum(populations).

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
  • Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Majority Labels over Audio IntervalsNooks · PHONE SCREEN
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
  • Hash Partition OffsetsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
  • Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
  • Product of Array Except SelfCapgemini · PHONE SCREENCapgemini interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public String selectCityByPopulation(String[] cities, int[] populations, int ticket) {
      // write your code here
    }
}
Checking account…