Country Population Density
Updated
Problem statement
A country lookup returns either no record or one record. In this practice, populations and areas are the corresponding numeric field projections. The arrays have the same length, either zero or one.
If both arrays are empty, return -1. Otherwise compute populations[0] / areas[0] and return the nearest integer. Round an exact half upward: for example, 12.5 becomes 13. A zero population has density zero.
The input already contains the extracted fields. No HTTP request or JSON parsing is required.
Function
populationDensity(populations: int[], areas: int[]) → intExamples
Example 1
populations = [1275840000]areas = [3287590]return = 388India has population 1275840000 and area 3287590. The quotient is between 388 and 389, and is closer to 388, so return 388.
Example 2
populations = [100]areas = [8]return = 13The density is 12.5. This practice rounds an exact half upward, so return 13.
Example 3
populations = []areas = []return = -1The lookup has no country record. Both field arrays are empty, so return -1.
Constraints
0 <= populations.length <= 1.0 <= areas.length <= 1.populations.length == areas.length.0 <= populations[i] <= 2147483647.1 <= areas[i] <= 2147483647.
More Palantir Online Assessment questions
- Basic Item DiscountsOA · Seen Nov 2026
- Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
- Stacked Item and Category DiscountsOA · Seen Nov 2026
- Minimize Path ValueOA · Seen Sep 2024
- No Pairs AllowedOA · Seen Sep 2024
- REST API: Country CodesOA · Seen Feb 2024
- Swap ParityOA · Seen Feb 2024
- Freelance Candidate ReviewOA · Seen Nov 2023
- Benchmarking Tool ReportOA · Seen Sep 2023
- Count Fit Records Across PagesOA · Seen Sep 2023
Similar questions at other companies
- Count Valid Square PairsAuxoAI · OA
- Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Maximum Student-Teacher DistanceChubb · OAChubb interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Minimum Password IncrementsAccenture · OAAccenture interview questions