PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving and data-manipulation skills, specifically date-based sorting, computing signed versus absolute adjacent differences, and correct handling of ordering and tie-breaking.

  • medium
  • Instacart
  • Coding & Algorithms
  • Software Engineer

Find Largest Adjacent Stock Price Change

Company: Instacart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an unsorted list of stock price records. Each record has two fields: - `date`: a date string in `YYYY-MM-DD` format - `price`: an integer stock price Sort the records by date in ascending order. Then find the adjacent pair of dates with the largest absolute price change. Return the signed price change, the earlier date, and the later date. The signed price change is calculated as: `later_price - earlier_price` If there are fewer than two records, return `null` or the language-appropriate equivalent. If multiple adjacent pairs have the same absolute price change, return the earliest such pair after sorting by date. Example: Input records: ```text Date: 2023-06-29, 2023-07-01, 2023-06-25, 2023-07-06 Price: 110, 112, 90, 105 ``` After sorting by date: ```text Date: 2023-06-25 -> 2023-06-29 -> 2023-07-01 -> 2023-07-06 Price: 90 -> 110 -> 112 -> 105 Change: +20 -> +2 -> -7 ``` The largest absolute adjacent change is `20`, which occurs between `2023-06-25` and `2023-06-29`. Expected output: ```text [20, "2023-06-25", "2023-06-29"] ```

Quick Answer: This question evaluates algorithmic problem-solving and data-manipulation skills, specifically date-based sorting, computing signed versus absolute adjacent differences, and correct handling of ordering and tie-breaking.

You are given an unsorted list of stock price records. Each record is a 2-item list in the form [date, price], where date is a string in YYYY-MM-DD format and price is an integer. First, sort the records by date in ascending order. Then examine each adjacent pair in the sorted list and find the pair with the largest absolute price change. For an adjacent pair, the signed price change is calculated as: later_price - earlier_price Return a list containing: [ signed_change, earlier_date, later_date ] If there are fewer than two records, return None. If multiple adjacent pairs have the same absolute price change, return the earliest such pair in the sorted order.

Constraints

  • 0 <= len(records) <= 200000
  • Each record contains a valid zero-padded date string in YYYY-MM-DD format and an integer price
  • Dates are distinct
  • 0 <= price <= 10^9

Examples

Input: [['2023-06-29', 110], ['2023-07-01', 112], ['2023-06-25', 90], ['2023-07-06', 105]]

Expected Output: [20, '2023-06-25', '2023-06-29']

Explanation: After sorting by date, the prices are 90 -> 110 -> 112 -> 105. The adjacent signed changes are 20, 2, and -7. The largest absolute change is 20, between 2023-06-25 and 2023-06-29.

Input: []

Expected Output: None

Explanation: There are no records, so no adjacent pair exists.

Input: [['2024-01-01', 150]]

Expected Output: None

Explanation: A single record does not form a pair.

Input: [['2023-01-03', 10], ['2023-01-01', 10], ['2023-01-02', 15]]

Expected Output: [5, '2023-01-01', '2023-01-02']

Explanation: After sorting, prices are 10 -> 15 -> 10. The adjacent changes are 5 and -5, both with absolute value 5. The earliest pair is returned.

Input: [['2023-01-03', 50], ['2023-01-01', 100], ['2023-01-02', 90], ['2023-01-04', 60]]

Expected Output: [-40, '2023-01-02', '2023-01-03']

Explanation: After sorting, prices are 100 -> 90 -> 50 -> 60. The adjacent changes are -10, -40, and 10. The largest absolute change is 40, from 2023-01-02 to 2023-01-03.

Hints

  1. Because the dates are in YYYY-MM-DD format, sorting the date strings lexicographically gives chronological order.
  2. Once the records are sorted, only neighboring records can form an adjacent pair. Track the largest absolute change, and on ties keep the first one you found.
Last updated: May 30, 2026

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
  • 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.

Related Coding Questions

  • Implement an In-Memory File Storage System - Instacart (medium)
  • Decode an encoded string - Instacart (medium)
  • Evaluate an arithmetic expression - Instacart (medium)
  • Implement worker time and payroll tracker - Instacart (hard)
  • Solve Two Sorted-Array Tasks - Instacart (hard)