PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Instacart

Solve Two Sorted-Array Tasks

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in array manipulation, handling of sorted data, search techniques and algorithmic complexity analysis, focusing on skills such as leveraging sorted order and reasoning about time and space trade-offs.

  • hard
  • Instacart
  • Coding & Algorithms
  • Machine Learning Engineer

Solve Two Sorted-Array Tasks

Company: Instacart

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Implement solutions for the following two array problems: 1. **Sorted values, return sorted squares** You are given an integer array sorted in non-decreasing order. The array may contain negative numbers. Return a new array containing the square of each value, also sorted in non-decreasing order. Example: Input: `[-7, -3, 0, 2, 5]` Output: `[0, 4, 9, 25, 49]` 2. **Find the first and last position of a target** You are given an integer array sorted in non-decreasing order and a target value. If the target appears multiple times, return the index of its leftmost occurrence and the index of its rightmost occurrence. If the target does not exist, return `[-1, -1]`. Example: Input: `nums = [1, 2, 2, 2, 3, 5]`, `target = 2` Output: `[1, 3]` Discuss the expected time and space complexity for each problem.

Quick Answer: This question evaluates competency in array manipulation, handling of sorted data, search techniques and algorithmic complexity analysis, focusing on skills such as leveraging sorted order and reasoning about time and space trade-offs.

Related Interview 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)
  • Implement store, evaluator, and parser - Instacart (hard)
Instacart logo
Instacart
Feb 10, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Implement solutions for the following two array problems:

  1. Sorted values, return sorted squares
    You are given an integer array sorted in non-decreasing order. The array may contain negative numbers. Return a new array containing the square of each value, also sorted in non-decreasing order. Example:
    Input: [-7, -3, 0, 2, 5]
    Output: [0, 4, 9, 25, 49]
  2. Find the first and last position of a target
    You are given an integer array sorted in non-decreasing order and a target value. If the target appears multiple times, return the index of its leftmost occurrence and the index of its rightmost occurrence. If the target does not exist, return [-1, -1] . Example:
    Input: nums = [1, 2, 2, 2, 3, 5] , target = 2
    Output: [1, 3]

Discuss the expected time and space complexity for each problem.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Instacart•More Machine Learning Engineer•Instacart Machine Learning Engineer•Instacart Coding & Algorithms•Machine Learning Engineer 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.