FastPrepCountry Population Density
Problems/Country Population Density

Country Population Density

Palantir logoPalantir● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Palantir new grad online assessment. The FDSE author describes taking a country's population and area and dividing them. A separate Palantir online assessment report gives the rounding to the nearest integer, the -1 for a missing country, and the India example used here.

Here, the fields come as two arrays with zero or one item each. We chose these rules: the population is a nonnegative 32-bit number, the area is a positive 32-bit number, and exact halves round up. The extra test data is ours. The HTTP and JSON parts are not part of the task.

Our version is about 65% the same as the FDSE report.

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[]) → int

Examples

Example 1

populations = [1275840000]areas = [3287590]return = 388

India 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 = 13

The density is 12.5. This practice rounds an exact half upward, so return 13.

Example 3

populations = []areas = []return = -1

The 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

Interview reports that mention this question

  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)

Palantir interview experiences

  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
  • Palantir FDSE Intern OA and Interviews: 3 Experiences
  • Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)
  • Palantir FDSE OA and Interviews: 16 Experiences (Part 1 of 2)
All Palantir interview questionsSee Palantir hiring insights
Saved
class Solution {
    public int populationDensity(int[] populations, int[] areas) {
        // Write your code here.
    }

}
Checking account…