← Palantir Interview Insights

Palantir·Software Engineer·Technical Phone Screen·Junior

JuniorPending
May 2026

Summary

First round at Palantir for a new grad SWE role, 45 minutes, one string manipulation problem. The interviewer was relaxed and helpful, and I came out of it cautiously optimistic but not confident.

Questions Asked (1)

Q1

Given a sentence and a query consisting of two words, plus an integer K, find all positions in the sentence where the first query word appears, then check whether the second query word shows up within K words after it. Return only the positions where both conditions are satisfied.

Algorithms & Data Structures
Author's notes

Lost a solid 10 minutes convinced there was some logic bug in my approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Tokenize the sentence into words while tracking each word's original position, then scan for occurrences of the first query word and check if the second word appears within the next K words. Collect and return the positions of the first word that satisfy the proximity condition.

Pro tip: Clarify upfront whether 'within K words after it' means strictly after (excluding the first word) and whether positions are 0-indexed or 1-indexed, and mention handling punctuation and case sensitivity—this shows attention to edge cases and real-world data quality.

1. Clarify requirements and edge cases

Confirm definitions: what counts as a word (punctuation handling), whether matching is case-sensitive, whether K counts words strictly after the first word, and whether positions are 0- or 1-indexed. Also ask about overlapping matches and empty inputs.

2. Tokenize and index the sentence

Split the sentence into words while preserving original positions (e.g., store each word with its index). Normalize case if needed and decide how to treat punctuation.

3. Find candidate positions for the first word

Iterate through the tokenized words and record every index where the first query word appears. These are the only positions that can potentially satisfy the condition.

4. Check proximity for the second word

For each candidate position, examine the next K words (or up to the end of the sentence) and check if the second query word occurs. If yes, add the candidate position to the result list.

5. Return results and discuss complexity

Return the list of valid positions. Analyze time complexity: O(N) to tokenize plus O(M*K) for checks, where M is the number of first-word occurrences; mention potential optimizations like precomputing second-word positions.

Key Points to Mention

  • Tokenization strategy and handling of punctuation/case sensitivity
  • Definition of 'within K words after' (strictly after, inclusive/exclusive boundaries)
  • Time and space complexity analysis, including worst-case scenarios
  • Edge cases: empty sentence, K=0, first word near end of sentence, overlapping matches
  • Potential optimization: precompute positions of the second word and use binary search or a sliding window
  • Indexing convention (0-based vs 1-based) and how to report positions

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.