Skip to content

Daily: 2026-10-17 — Best Time to Buy and Sell Stock - #5

Merged
GAjay merged 1 commit into
mainfrom
daily/2026-10-17-best-time-to-buy-sell-stock
Oct 17, 2026
Merged

GAjay merged 1 commit into
mainfrom
daily/2026-10-17-best-time-to-buy-sell-stock

Conversation

@cursor

@cursor cursor Bot commented Oct 17, 2026

Copy link
Copy Markdown

Problem

  • Slug: best-time-to-buy-sell-stock
  • Folder: problems/2026-10-17-best-time-to-buy-sell-stock/

Approach

One pass over prices, keeping the lowest price seen so far and the best profit achievable by selling at the current day. Update max profit as price - minPrice whenever the current price exceeds the running minimum. Return 0 when no profitable pair exists.

Tests

node --test problems/2026-10-17-best-time-to-buy-sell-stock/best-time-to-buy-sell-stock.test.js
npm run test:ci

All tests passed.

Open in Web View Automation 

@GAjay
GAjay force-pushed the daily/2026-10-17-best-time-to-buy-sell-stock branch from f3a4f7b to 410e861 Compare October 17, 2026 07:00
@GAjay
GAjay marked this pull request as ready for review October 17, 2026 07:00
@GAjay
GAjay merged commit 28865e2 into main Oct 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant