PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Two Sigma

Evaluate a Piecewise Linear Function

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of linear interpolation, numerical reasoning with ordered 2D points, and input validation when computing values on a piecewise linear function.

  • medium
  • Two Sigma
  • Coding & Algorithms
  • Data Scientist

Evaluate a Piecewise Linear Function

Company: Two Sigma

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an ordered list of 2D points `[(x1, y1), (x2, y2), ..., (xn, yn)]`. Connecting each consecutive pair of points forms a piecewise linear function. Given a target value `target_x`, return the corresponding `y` value on the function at that x-coordinate. Assume: - The points are ordered by increasing `x`. - The function is defined by straight-line interpolation between consecutive points. - `target_x` may coincide with an existing point or fall between two adjacent points. Clarify how you would handle edge cases such as: - `target_x` outside the covered x-range - duplicate x-values - invalid input with fewer than 2 points Example: - Points: `[(1, 2), (3, 6), (5, 4)]` - `target_x = 2` - Output: `4`, because the point lies on the line segment between `(1, 2)` and `(3, 6)`.

Quick Answer: This question evaluates understanding of linear interpolation, numerical reasoning with ordered 2D points, and input validation when computing values on a piecewise linear function.

Related Interview Questions

  • Implement Price-Time Order Matching - Two Sigma (medium)
  • Compute Piecewise Linear Interpolation - Two Sigma (medium)
  • Implement an In-Memory Database - Two Sigma (hard)
  • Merge two sorted linked lists - Two Sigma (hard)
  • Merge Two Sorted Lists - Two Sigma (hard)
Two Sigma logo
Two Sigma
Mar 3, 2026, 12:00 AM
Data Scientist
Take-home Project
Coding & Algorithms
2
0
Loading...

You are given an ordered list of 2D points [(x1, y1), (x2, y2), ..., (xn, yn)]. Connecting each consecutive pair of points forms a piecewise linear function.

Given a target value target_x, return the corresponding y value on the function at that x-coordinate.

Assume:

  • The points are ordered by increasing x .
  • The function is defined by straight-line interpolation between consecutive points.
  • target_x may coincide with an existing point or fall between two adjacent points.

Clarify how you would handle edge cases such as:

  • target_x outside the covered x-range
  • duplicate x-values
  • invalid input with fewer than 2 points

Example:

  • Points: [(1, 2), (3, 6), (5, 4)]
  • target_x = 2
  • Output: 4 , because the point lies on the line segment between (1, 2) and (3, 6) .

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Two Sigma•More Data Scientist•Two Sigma Data Scientist•Two Sigma Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.