FastPrepRelational Learning Queries
Problems/Relational Learning Queries

Relational Learning Queries

Palantir logoPalantir● EasyNEW GRADFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Palantir onsite interview. The report describes learning one-to-many and many-to-many relations, then finishing functions with a given Python-object Query Builder. It says clearly that the interface is not an ORM.

The original tables, query goals, and private interface were not shared. The enrollment tables, the guide to the operations, the three queries, the rules, the limits, and the examples here are our own choices. Our version does not run the original private API.

Our version is about 50% the same as the reported question.

For this exercise, assume a small enrollment database has student IDs, course IDs and a relation between them. Each row of enrollments is [student, course]. A student can join several courses, and a course can have several students.

Use this operation guide to read the relations:

  • select(rows, predicate) keeps the rows satisfying a condition, in their original order.
  • project(rows, column) returns that column from each selected row, in order.
  • related(key, rows, column) selects the relation rows whose chosen column equals the key.
  • count(rows) returns the number of selected rows.

For example, if enrollment rows are [[1,20],[1,10],[2,20]], selecting student 1 and projecting the course column gives [20,10]. Sorting that query result gives [10,20].

Implement enrollmentQueries and return exactly three integer rows:

  1. All course IDs related to studentId, in increasing order.
  2. All student IDs related to courseId, in increasing order.
  3. The number of enrolled students for every course, aligned with the original order of courseIds. Include zero for a course with no enrollments.

The first two rows are empty when they have no matches. The relation contains no repeated student-course pair. Use ordinary loops or your language's query tools; no external helper library, SQL string renderer or ORM is required.

Function

enrollmentQueries(studentIds: int[], courseIds: int[], enrollments: int[][], studentId: int, courseId: int) → int[][]

Examples

Example 1

studentIds = [1,2]courseIds = [20,10,30]enrollments = [[1,20],[1,10],[2,20]]studentId = 1courseId = 20return = [[10,20],[1,2],[2,1,0]]

Student 1 joins courses 20 and 10, so the first row is [10,20]. Course 20 has students 1 and 2. Course counts follow [20,10,30], giving [2,1,0].

Example 2

studentIds = [7]courseIds = [40,10]enrollments = []studentId = 7courseId = 10return = [[],[],[0,0]]

No enrollment exists. Both selected relations are empty, and both course counts are zero. The result is [[],[],[0,0]].

Example 3

studentIds = [10,2,1000000]courseIds = [50,10,1]enrollments = [[1000000,1],[2,10],[10,1],[2,50]]studentId = 2courseId = 1return = [[10,50],[10,1000000],[1,1,2]]

Student 2 joins courses 10 and 50. Course 1 has students 10 and 1000000. Counts for courses [50,10,1] are [1,1,2]; this row keeps the input course order.

Constraints

  • 1 <= studentIds.length <= 50 and 1 <= courseIds.length <= 50.
  • 0 <= enrollments.length <= 200.
  • Every enrollment row contains exactly 2 integers.
  • Every ID, including both query IDs and every enrollment entry, is in [1, 1000000].
  • Student IDs are distinct, course IDs are distinct, and enrollment pairs are distinct.
  • Every enrollment student belongs to studentIds, and every enrollment course belongs to courseIds.
  • studentId belongs to studentIds, and courseId belongs to courseIds.

More Palantir interview questions

  • Map and Accumulate Learning QueriesONSITE INTERVIEW · Seen Oct 2026
  • Find Unmet Users With Shared InterestsONSITE INTERVIEW · Seen Mar 2025
  • Maximum Profit with Repeated Stock TradesONSITE INTERVIEW · Seen Sep 2024
  • Minimum Calls for Repeated API LookupsONSITE INTERVIEW · Seen Oct 2022
  • Find Cookable RecipesONSITE INTERVIEW · Seen Nov 2019
  • Simulate Multiplayer WarONSITE INTERVIEW · Seen Nov 2019
  • Trace Terminal Company OwnershipONSITE INTERVIEW · Seen Nov 2019
  • Query Words Within K PositionsPHONE SCREEN · Seen Nov 2026
  • Basic Item DiscountsOA · Seen Nov 2026
  • Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
  • Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
  • High-Severity Counts by Search TypeChainalysis · ONSITE INTERVIEWChainalysis interview questions
  • Intersection of Two ListsJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Pair Left and Right Socks by IDRoblox · ONSITE INTERVIEWRoblox interview questions
  • Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
  • Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions

Interview reports that mention this question

  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)

Palantir interview experiences

  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 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[][] enrollmentQueries(int[] studentIds, int[] courseIds, int[][] enrollments, int studentId, int courseId) {
        return new int[0][];
    }
}
Checking account…