---
id: TASK-28
title: 'Разбор задачи: Best Time to Buy and Sell Stock with Transaction Fee (Greedy)'
status: Done
assignee:
  - '@assistant'
created_date: '2026-09-10 07:50'
updated_date: '2026-09-10 08:57'
labels: []
dependencies: []
references:
  - applications/yandex-codenv/algo-solutions/_template.md
modified_files:
  - >-
    applications/yandex-codenv/algo-solutions/greedy/03-best-time-to-buy-and-sell-stock-with-transaction-fee.md
priority: high
type: task
ordinal: 28000
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Файл: algo-solutions/greedy/03-best-time-with-transaction-fee.md. **DP** с двумя состояниями (hold/cash).
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Файл создан со всеми секциями формата
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1. Create file at applications/yandex-codenv/algo-solutions/greedy/03-best-time-to-buy-and-sell-stock-with-transaction-fee.md
2. Follow established template format (frontmatter, sections: Условие, Ключевая идея, Оценка сложности, Решение, Разбор, Edge Cases, Типичные ошибки, Альтернативные подходы)
3. Implement DP with two states (hold/cash): cash = max(cash, hold + price - fee), hold = max(hold, cash - price)
4. Run a quick Ruby test to verify the solution
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Solution verified with Ruby: all 7 test cases pass (both LeetCode examples + 5 edge cases).
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Created applications/yandex-codenv/algo-solutions/greedy/03-best-time-to-buy-and-sell-stock-with-transaction-fee.md with DP two-states (hold/cash). Verified with Ruby — 7/7 test cases pass including both LeetCode examples and edge cases (single element, all equal, fee exceeds diff, one profitable trade, rising market).
<!-- SECTION:FINAL_SUMMARY:END -->
