PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Apple

Solve stock and banana problems

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving skills related to array processing, optimization under constraints, and reasoning about performance trade-offs by presenting a maximum single-transaction stock profit problem and a minimum banana-eating speed problem.

  • medium
  • Apple
  • Coding & Algorithms
  • Machine Learning Engineer

Solve stock and banana problems

Company: Apple

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Solve both coding problems below. 1. **Maximum single-transaction stock profit**: Given an array `prices` where `prices[i]` is the stock price on day `i`, return the maximum profit obtainable by choosing one day to buy and a later day to sell. If no profit is possible, return `0`. 2. **Minimum banana-eating speed**: Given an array `piles` where `piles[i]` is the number of bananas in pile `i`, and an integer `h` representing the total number of hours available, find the minimum integer eating speed `k` such that a monkey can finish all piles within `h` hours. In one hour, the monkey chooses one pile and eats up to `k` bananas from that pile. For each problem, explain your algorithm and analyze time and space complexity.

Quick Answer: This question evaluates algorithmic problem-solving skills related to array processing, optimization under constraints, and reasoning about performance trade-offs by presenting a maximum single-transaction stock profit problem and a minimum banana-eating speed problem.

Related Interview Questions

  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
  • Rotate a Matrix In Place - Apple (medium)
  • Encode and Rebuild a Binary Tree - Apple (hard)
  • Wrap Matching Substrings in Bold Tags - Apple (medium)
Apple logo
Apple
Dec 17, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
2
0

Solve both coding problems below.

  1. Maximum single-transaction stock profit : Given an array prices where prices[i] is the stock price on day i , return the maximum profit obtainable by choosing one day to buy and a later day to sell. If no profit is possible, return 0 .
  2. Minimum banana-eating speed : Given an array piles where piles[i] is the number of bananas in pile i , and an integer h representing the total number of hours available, find the minimum integer eating speed k such that a monkey can finish all piles within h hours. In one hour, the monkey chooses one pile and eats up to k bananas from that pile.

For each problem, explain your algorithm and analyze time and space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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