The TransCompilator

Solved LeetCode program · 508 of 1,000

#0714 · Best Time to Buy and Sell Stock with Transaction Fee

Medium Array chunk-11.md

Original English source

The prices is a list of 1, 3, 2, 8, 4, and 9. The fee is 2. The cash is 0. The hold is 0 minus item 0 of prices.
For every spot from 1 to the last position of prices.
The price is item spot of prices. The sell is hold plus price minus fee. If sell is more than cash, set cash to sell. The buy is cash minus price. If buy is more than hold, set hold to buy.

Show cash.

Open in Playground Browse all 1,000 problems

Expected stdout

8