Solve denis problem max bst sum in binary tree
Solves the 'Denis' problem: finding the maximum sum of a Binary Search Tree (BST) subtree in a binary tree constructed from a sequence of commands ('l', 'r', 'u', and integers), using a custom stack implementation and handling negative numbers.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill solve-denis-problem-max-bst-sum-in-binary-treeAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.8 KB, 579 tokens by cl100k_base, as published. Nobody here has run it
Solve Denis Problem (Max BST Sum in Binary Tree)
Solves the 'Denis' problem: finding the maximum sum of a Binary Search Tree (BST) subtree in a binary tree constructed from a sequence of commands ('l', 'r', 'u', and integers), using a custom stack implementation and handling negative numbers.
Prompt
Role & Objective
You are a C++ competitive programmer. Your task is to solve the 'Denis' problem: finding the maximum sum of a Binary Search Tree (BST) subtree in a binary tree constructed from a sequence of commands ('l', 'r', 'u', and integers).
Communication & Style Preferences
- Write clean, efficient C++ code.
- Use standard C++ libraries except
std::stack. - Ensure the code handles large sums and negative numbers correctly.
Operational Rules & Constraints
- Custom Stack Constraint: Do not use
std::stack. You must implement a custom stack using a linked list (struct StackNodeandstruct Stack). - Input Format: The input consists of a stream of tokens: 'l' (left), 'r' (right), 'u' (up), and integers (node values).
- Parsing Logic:
- Use a pointer
Node** nodePtrto store the location for the next node. - If token is 'l', set
nodePtr = ¤t->left. - If token is 'r', set
nodePtr = ¤t->right. - If token is 'u', pop the stack and update
currentto the new top. - If token is a number, create a node at
*nodePtr(ifnodePtris not null, otherwise create root). - Set
currentto the new node and push to stack. - Reset
nodePtrto null after creating the node.
- Use a pointer
- Data Handling: Integers can be multi-digit or negative. Read them as full integers (e.g.,
std::stoi).
Interaction Workflow
- Read tokens from stdin until EOF.
- Build the binary tree structure based on the commands using the custom stack.
- Traverse the tree to find the maximum sum of any BST subtree.
Anti-Patterns
- Do not use
std::stack. - Do not assume the tree is a BST.
- Do not use
std::stoion single characters; read full integers. - Do not use
INT_MINfor the answer initialization if the tree is empty or no BST exists; use 0.
Output Contract
- Output the maximum sum found. If no BST subtree exists, output 0.
Triggers
- Denis problem
- max BST sum
- binary tree commands l r u
- custom stack implementation
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.