PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving, practical coding implementation, complexity analysis, testing rigor, and the ability to discuss design trade-offs across topics such as arrays, strings, hash maps, and graphs.

  • medium
  • Palantir
  • Coding & Algorithms
  • Software Engineer

Solve two algorithm problems from a menu

Company: Palantir

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Choose two problems from an algorithms menu (arrays, strings, hash maps, graphs). For each: 1) state clarifying assumptions, 2) implement a correct solution in your preferred language, 3) analyze time and space complexity, 4) provide tests for edge cases and large inputs, and 5) discuss alternative approaches and trade-offs.

Quick Answer: This question evaluates algorithmic problem-solving, practical coding implementation, complexity analysis, testing rigor, and the ability to discuss design trade-offs across topics such as arrays, strings, hash maps, and graphs.

Part 1: Longest Consecutive Sequence

Given an unsorted list of integers, return the length of the longest sequence of consecutive integer values. The values do not need to appear next to each other in the original list. Duplicate numbers do not extend a sequence. Assume an empty list returns 0.

Constraints

  • 0 <= len(nums) <= 200000
  • -10^9 <= nums[i] <= 10^9
  • The input may contain duplicate values
  • Return 0 when the input list is empty

Examples

Input: ([100, 4, 200, 1, 3, 2],)

Expected Output: 4

Explanation: The longest consecutive sequence is [1, 2, 3, 4], so the answer is 4.

Input: ([0, 3, 7, 2, 5, 8, 4, 6, 0, 1],)

Expected Output: 9

Explanation: The numbers 0 through 8 are all present, giving a longest sequence length of 9.

Hints

  1. Fast membership checks are useful when repeatedly asking whether x - 1 or x + 1 exists.
  2. You only need to start counting from numbers that are the beginning of a sequence.

Part 2: Number of Islands

Given a rectangular grid of 0s and 1s, count how many islands it contains. An island is a maximal group of 1 cells connected horizontally or vertically. Diagonal cells do not connect islands. Assume an empty grid, or a grid with zero columns, contains 0 islands.

Constraints

  • 0 <= number of rows <= 1000
  • 0 <= number of columns <= 1000
  • For non-empty grids, rows * columns <= 200000
  • The grid is rectangular
  • Connectivity is 4-directional only: up, down, left, right

Examples

Input: (([[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1]]),)

Expected Output: 3

Explanation: There are three separate groups of connected land cells.

Input: ([],)

Expected Output: 0

Explanation: An empty grid contains no land and therefore no islands.

Hints

  1. Treat each land cell as a node in a graph and explore its connected component.
  2. Each time you discover an unvisited land cell, traverse its whole island and increment the answer once.
Last updated: Apr 22, 2026

Related Coding Questions

  • Find Shortest Paths in Road Network - Palantir (easy)
  • Group employees by shared interests - Palantir (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.