🌐
LeetCode
leetcode.com › discuss › interview-question › 960222 › negative-balancing
Discuss - LeetCode
December 5, 2020 - The Geek Hub for Discussions, Learning, and Networking.
🌐
AlgoMonster
algo.monster › liteproblems › 465
465. Optimal Account Balancing - In-Depth Explanation
In-depth solution and explanation for LeetCode 465. Optimal Account Balancing in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
Hello Interview
hellointerview.com › community › questions › optimal-account-balancing › cm5eguhab02db838o1qbyie4f
Leetcode 465. Optimal Account Balancing | Hello Interview
Given a list of money transfers among people, compute the minimum number of transactions required to settle all debts so every person's net balance becomes zero. After aggregating net balances, the core challenge is to cancel out positive and negative balances optimally—typically solved with backtracking/bitmask DP and aggressive pruning to find the fewest transactions.
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0400-0499 › 0465.Optimal Account Balancing › README_EN.md
leetcode/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md at main · doocs/leetcode
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解 - leetcode/solution/0400-0499/0465.Optimal Account Balancing/README_EN.md at main · doocs/leetcode
Author   doocs
🌐
AlgoMap
algomap.io › problems › optimal-account-balancing
465. Optimal Account Balancing - Leetcode Solution
By focusing on each person's net ... debts. Pruning and skipping zero balances greatly improve performance. The solution is elegant because it reduces a seemingly complex set of transactions to a problem of pairing up positive and negative balances optimally....
🌐
GitHub
github.com › giangkhuat › Problems-solved-on-HackerRank
GitHub - giangkhuat/Problems-solved-on-HackerRank: Problems solved from HackerRank, Leetcode and Pramp · GitHub
Problem Statement:Given an array ... of the numbers in arr. If two numbers have the same absolute value, sort them according to sign, where the negative numbers come before the positive numbers....
Starred by 4 users
Forked by 4 users
Languages   Java
🌐
Stack Overflow
stackoverflow.com › questions › 74869133 › understanding-solution-to-the-optimal-account-balancing-leetcode-465-in-python
algorithm - Understanding solution to the Optimal Account Balancing (Leetcode 465) in python - Stack Overflow
Thirdly, I have come up with my solution to this problem which is at the bottom of this post. I used plain backtracking but when it comes to analyzing the time complexity, I am slightly uncertain. My intuition is that since for loop inside the 'backtrack' function is going from 0 -> len(balance) then 1-> len(balance) ...
🌐
Taro
jointaro.com › interviews › optimal account balancing
Optimal Account Balancing Interview Question - Taro
Some will have a zero balance (they are settled). Combine all the positive and negative balance values, ignoring the zeros.
Find elsewhere
🌐
HackerRank
hackerrank.com › challenges › luck-balance › problem
Luck Balance | HackerRank
If Lena wins the contest, her luck balance will decrease by ; if she loses it, her luck balance will increase by . denotes the contest's importance rating. It's equal to if the contest is important, and it's equal to if it's unimportant.
🌐
Medium
medium.com › @xerene804 › tiktok-swe-interview-question-leetcode-465-optimal-account-balancing-02c2e055dbc1
Tiktok SWE Interview Question: Leetcode 465. Optimal Account Balancing | by Xerene | Medium
March 26, 2024 - net_balances = {} for giver, receiver, cash_flow in transactions: net_balances.setdefault(giver, 0) net_balances.setdefault(receiver, 0) net_balances[giver] -= cash_flow net_balances[receiver] += cash_flow # Remove entries for participants whose ...
🌐
Haifengjin
notes.haifengjin.com › competitive_programming › leetcode › 465
465. Optimal Account Balancing - Haifeng's Notes
First, we calculate how much money each person owns (can be positive or negative). Then, we just use DFS to settle the debt. One person will return all his debt to another person. The DFS will search every choice of choosing the person.
🌐
Blogger
massivealgorithms.blogspot.com › 2016 › 11 › leetcode-465-optimal-account-balancing.html
Massive Algorithms: LeetCode 465 - Optimal Account Balancing
November 20, 2016 - Now, we have some negative account changes and positive account changes. By the way it is not hard to see that they compensate each other. Now, our task is to balance the accounts, by performing minimal amount of transactions. For instance we can balance these accounts, by performing the following transactions: [1,2,2], [3,4,5], [1,4,1]. After that, all accounts become balanced, i.e 0 extra money in total.
🌐
GitHub
github.com › shressur › Smallest-Negative-Balance
GitHub - shressur/Smallest-Negative-Balance
Contribute to shressur/Smallest-Negative-Balance development by creating an account on GitHub.
Author   shressur
🌐
LeetCode
leetcode.ca › all › 465.html
465. Optimal Account Balancing - leetcode.ca
465-Optimal-Account-Balancing · Link to All Problems · All contents and pictures on this website come from the Internet and are updated regularly every week. They are for personal study and research only, and should not be used for commercial purposes.
🌐
Reddit
reddit.com › r/leetcode › don't understand lc 110, balanced binary tree
r/leetcode on Reddit: Don't understand LC 110, Balanced Binary Tree
October 17, 2023 -

Hey guys, I've been trying to pass the balanced binary tree LC and I couldn't figure it out myself, so I referenced a recursive solution. I'm having a hard time wrapping my head around the solution and why it works. The code is below:

class Solution {
public:
bool isBalanced(TreeNode* root) {
int height = 0;
return dfs(root, height);
}
public:
bool dfs(TreeNode* root, int &height) {
if(root == NULL){
height = -1;
return true;
}
int left = 0;
int right = 0;
if(!(dfs(root -> left, left)) || !(dfs(root -> right, right))){
return false;
}
if(abs(left - right) > 1){
return false;
}
height = 1 + max(left, right);
return true;
}
};

I'm kinda confused as to how left and right are used. To my understanding, the first if statement is making sure it's not an empty tree, and the height = -1 is useless? And the coder basically declared the left and right int variables to keep track of the depth of the tree for both the left and the right nodes. The next if statement iterates through the tree, and left/right are used as the new height for the next node, and the next if statement tells us whether the condition of being a balanced tree good or not. Lastly, I believe the height is updated by 1 + the deepest node because we go down one node further? And if the function goes up the call stack and returns true for all of them, the node is balanced. However, I'm not too sure how left and right are updated since I only see them set equal to 0. I guess I'm just not quite sure how the height and everything is updated. Sorry if my understanding is really confusing I just find it really hard to wrap my head around recursion, any help would be great thanks!

🌐
LeetCode
leetcode.com › discuss › interview-question › 609750 › google-phone-optimal-account-balancing
Google | Phone | Optimal Account Balancing - Discuss - LeetCode
Question simplify debt: In a group of people: Mary owes Adam 100$ Adam owes Chan 100$ Chan Owes Mary 100$ So we should do no transaction at all bec