# The Palantir HackerRank task that punishes stopping at page one

> In an auto-graded round, one missed page of data or one stray debug line is enough to fail, so this walkthrough rebuilds the task step by step.

Original: https://fdetimes.net/en/guides/palantir-hackerrank-pagination-api-task/

A post signed by Seraphina on Linkjob, a commercial interview-prep site, recounts a Palantir online assessment taken on HackerRank. One of the tasks, titled "TV Shows Produced During a Period", asked candidates to use HTTP GET to retrieve information about recent TV series from `jsonmock.hackerrank.com/api/tvseries`.

The author writes that the test lasted 90 minutes and had three questions, but the timeline section of the same post says one hour. Treat it as one person's account, not an official format.

The task type turns up elsewhere all the same. An unofficial guide from InterviewFox also describes an API problem on a paginated JSON endpoint, where every page must be fetched before a field is aggregated.

InterviewFox names stopping at page one as the most common mistake. It is also a mistake you can make when pulling data from a client's system, so drilling this problem pays off both in the assessment and later on the job as an FDE.

## What you will build and what you need

You will write a Python script that fetches all 200 records from the mock API, extracts each series' start year, filters by a range of years and prints the result in exactly the right format. You need Python 3 and the `requests` library.

According to HackerRank's Execution Environment page, the Python 3 environment runs Python 3.14.2 with a 10-second limit and 512 MB of memory, and ships with `requests` 2.25.1. The page does not say whether code can reach the internet, so read the problem carefully before assuming it can.

## Step 1: call the first page, with a timeout

The Requests documentation says a request will not time out unless you set a timeout, and recommends using the parameter on nearly every production request, because without it a program can hang indefinitely. The same documentation points out that a successful `r.json()` call does not mean the request succeeded.

```python
import requests

BASE = "https://jsonmock.hackerrank.com/api/tvseries"

def get_page(page):
    r = requests.get(BASE, params={"page": page}, timeout=5)
    r.raise_for_status()   # 4xx/5xx stops here instead of silently parsing an error body
    return r.json()

first = get_page(1)
print({k: first[k] for k in ("page", "per_page", "total", "total_pages")})
```

What to check: when called on 2026-11-27, page 1 returned `page` 1, `per_page` 10, `total` 200 and `total_pages` 20. The value `timeout=5` is a number chosen for practice, not an official recommendation.

## Step 2: look at a real record before writing the filter

According to the Linkjob account, the response has five fields: `page`, `per_page`, `total`, `total_pages` and `data`. The records sit in `data`, so print one to see the real field names.

```python
print(first["data"][0]["name"], first["data"][0]["runtime_of_series"])
# Game of Thrones (2011-2019)
```

Each record has the fields `name`, `runtime_of_series`, `certificate`, `runtime_of_episodes`, `genre`, `imdb_rating`, `overview`, `no_of_votes` and `id`. The one to watch is `runtime_of_series`: it is a string, not a number, and it has no fixed shape.

Open page 20 as well. The Titans record has the value `"(I) (2018- )"`: an extra `(I)` prefix before the year, and a blank end year because the show is still running. Slice the string at fixed positions, as in `s[1:5]`, and Titans is read wrongly.

## Step 3: walk all 20 pages without being off by one

The arithmetic is simple: 200 records at 10 per page is 20 pages and 20 GET requests. The classic mistake is writing `range(1, total_pages)`, because the upper bound of `range` is excluded. The loop then stops at page 19 and the last 10 records vanish without any error.

```python
def fetch_all():
    first = get_page(1)
    rows = list(first["data"])
    for p in range(2, first["total_pages"] + 1):
        rows.extend(get_page(p)["data"])
    return rows

rows = fetch_all()
print(len(rows), len(rows) == 200)   # expected: 200 True
```

The opposite mistake is just as silent. Request page 21, one past `total_pages`, and the API still returns normal metadata with an empty `data` rather than an error, so the data gives no sign that the loop overran.

Taking `total_pages` from the first page is therefore safer than probing until an empty page appears, and it saves a request. If the 10-second limit applies to the whole task, 20 sequential calls get half a second each on average.

## Step 4: extract the year, filter, then print every character right

For practice, say the problem asks for the names of series that started between 2010 and 2015. Rather than slicing by position, take the first four-digit group in the string. That handles both `"(2011-2019)"` and `"(I) (2018- )"`.

```python
import re

def start_year(row):
    years = re.findall(r"\d{4}", row.get("runtime_of_series") or "")
    return int(years[0]) if years else None

def produced_between(rows, start, end):
    out = []
    for r in rows:
        y = start_year(r)
        if y is not None and start <= y <= end:
            out.append(r["name"])
    return out

for name in produced_between(first["data"], 2010, 2015):
    print(name)
```

What to check: run on page 1 alone, the result must contain exactly four names: Game of Thrones, The Walking Dead, Sherlock and True Detective. Then pass the Titans record to `start_year()` and confirm it returns 2018.

The code above is a trimmed version. The year range, the comparison and the print order must follow the problem you actually receive: if it asks for names sorted alphabetically, wrap the result in `sorted()`; if it asks the function to return a list, `return` instead of printing.

Using `row.get(...) or ""` keeps a record with a missing or empty field from crashing the whole program. HackerRank says hidden tests are used to check edge cases for correctness and performance, and odd records like Titans are exactly the kind of data likely to sit there.

**Key point:** An auto-grader does not read your intent; it compares every character you print.

## The mistakes that cost strong candidates points

HackerRank grades coding questions by exact string matching, so output must match the expected result precisely. For problems graded on printed output, HackerRank advises removing every debug `print` before submitting. The `print(len(rows), ...)` line in Step 3 is useful in practice, but leaving it in is enough to fail.

The second trap is custom input. When you run with your own input, HackerRank runs your logic only on that value; the problem's test cases are not executed. Debug prints with custom input are fine for inspecting logic, but run again against the provided tests afterward.

## What this skill looks like at a client site

An unofficial guide from Aced lists a sample question for Palantir's FDE technical screen: write a function that fetches paginated data from a REST API, handling page size and total-page logic. Every mistake in the exercise above has a counterpart in real systems.

At a client site, a request with no timeout can hang indefinitely and take a whole sync job down with it. A loop that is off by one page loses data without raising an error.

A positional parser fails quietly on precisely the unusual records clients tend to notice most. The `len(rows) == total` comparison in Step 3 is the kind of reconciliation worth running before reporting any number.

On a CV, do not stop at "integrated REST APIs". State how many records you synced, that you reconciled them against the total the source reported, and how you handled timeouts and irregular data. If pagination comes up in an interview, let the interviewer see that reconciliation habit.

**Try this week:**

- Write fetch_all() for jsonmock.hackerrank.com/api/tvseries in 20 minutes, then check that you got all 200 records.
- Run the 2010–2015 filter on page 1 alone and compare the output with the four names Game of Thrones, The Walking Dead, Sherlock, True Detective.
- Pass the Titans record from page 20 to your start_year() function and confirm it returns 2018.

## Sources

- [My 2026 Palantir Interview Process and Actual Questions](https://www.linkjob.ai/interview-questions/palantir-interview-process-questions/)

- [I Aced Palantir HackerRank in 2026: Real Questions and Prep Plan](https://interviewfox.ai/interview-questions/palantir-hackerrank/)

- [Palantir Forward Deployed Engineer (FDE) Interview Guide](https://www.aced.io/guides/palantir-forward-deployed-engineer-interview)

- [jsonmock.hackerrank.com/api/tvseries?page=1 (JSON response)](https://jsonmock.hackerrank.com/api/tvseries?page=1)

- [jsonmock.hackerrank.com/api/tvseries?page=20 (JSON response)](https://jsonmock.hackerrank.com/api/tvseries?page=20)

- [jsonmock.hackerrank.com/api/tvseries?page=21 (JSON response)](https://jsonmock.hackerrank.com/api/tvseries?page=21)

- [Quickstart — Requests documentation](https://requests.readthedocs.io/en/latest/user/quickstart/)

- [Execution Environment](https://support.hackerrank.com/articles/6693750503-execution-environment)

- [Answer Coding Questions](https://candidatesupport.hackerrank.com/articles/9623161883-answer-coding-questions)

- [Debug Using Custom Input Values](https://candidatesupport.hackerrank.com/articles/2715283041-debug-using-custom-input-values)
