Skip to content

Conversation

@yanglbme
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings December 14, 2025 11:37
@idoocs idoocs added core team Issues or pull requests from core team md Issues or Pull requests relate to .md files labels Dec 14, 2025
@yanglbme yanglbme merged commit a0239dd into main Dec 14, 2025
13 of 14 checks passed
@yanglbme yanglbme deleted the dev branch December 14, 2025 11:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a complete solution to LeetCode problem #3562 "Maximum Profit from Trading Stocks with Discounts", a hard-level dynamic programming problem from Weekly Contest 451. The problem involves optimizing stock purchases in a company hierarchy where employees can get discounted prices if their direct boss purchases stock.

Key Changes:

  • Implements a tree-based DP solution using DFS traversal
  • Handles budget constraints and hierarchical discount mechanics
  • Provides comprehensive documentation in both Chinese and English

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Solution.py Python implementation using custom max lambda and recursive DFS with memoization
Solution.java Java implementation with instance variables for cleaner recursive calls
Solution.cpp C++ implementation using lambda with capture for concise DFS logic
Solution.go Go implementation with closure-based DFS approach
Solution.ts TypeScript implementation with clear variable naming for readability
README.md Chinese problem description with examples and constraints
README_EN.md English problem description with detailed explanations

Technical Approach:
All implementations use a consistent tree DP strategy where f[j][pre] represents the maximum profit achievable with budget j, where pre indicates whether the parent node purchased stock (affecting discount availability). The solutions correctly handle:

  • Building the tree structure from the hierarchy array
  • Computing optimal stock purchase decisions at each node
  • Managing budget allocation across the tree
  • Applying the 50% discount when parent purchases stock

Code Quality Notes:

  • All implementations follow consistent logic and produce correct results
  • The Python solution uses a custom max lambda that shadows the built-in function (a minor style concern but functionally correct)
  • Solutions are well-structured with clear separation of tree building and DP computation phases
  • Time complexity: O(n × budget² × 2) where n is the number of employees
  • Space complexity: O(n + budget) for the recursion stack and DP arrays

The solutions are algorithmically sound and handle all the problem constraints correctly, including edge cases with budget limitations and the hierarchical discount policy.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core team Issues or pull requests from core team md Issues or Pull requests relate to .md files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants