how to know if a node is an ancestor of another node in a tree?
first let's have a global variable that tracks time, which starts from zero.
when traversing the tree using dfs, track the "in" and "out" time of each node.
- "in" time = is the time at which the recursive dfs function is on that node.
- "out" time = is the time after the dfs function traversed every child and grand children of the current node.
to show it in code.
let "x" be a node and "y" be another that node. then we can check "x" is an ancestor of "y",
if in(x) < in(y) < out(x).
#lessons
first let's have a global variable that tracks time, which starts from zero.
when traversing the tree using dfs, track the "in" and "out" time of each node.
- "in" time = is the time at which the recursive dfs function is on that node.
- "out" time = is the time after the dfs function traversed every child and grand children of the current node.
to show it in code.
def dfs(node):
# "in" time is here
for child in graph[node]:
dfs(child)
# "out" time is here
let "x" be a node and "y" be another that node. then we can check "x" is an ancestor of "y",
if in(x) < in(y) < out(x).
#lessons
Binlogs
how to know if a node is an ancestor of another node in a tree? first let's have a global variable that tracks time, which starts from zero. when traversing the tree using dfs, track the "in" and "out" time of each node. - "in" time = is the time at which…
AtCoder
E - Count Descendants
AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.
LeetCode
Find Sum of Array Product of Magical Sequences - LeetCode
Can you solve this real interview question? Find Sum of Array Product of Magical Sequences - You are given two integers, m and k, and an integer array nums.
A sequence of integers seq is called magical if:
* seq has a size of m.
* 0 <= seq[i] < nums.length…
A sequence of integers seq is called magical if:
* seq has a size of m.
* 0 <= seq[i] < nums.length…
https://leetcode.com/problems/find-sum-of-array-product-of-magical-sequences/
I couldn't solve it. can you?
I couldn't solve it. can you?
Forwarded from DoughNut 🍩
Looking for those cool isometric shapes on websites? Here's a tool that has a bunch of them
https://www.isocons.app/
#Frontend
https://www.isocons.app/
#Frontend
Isocons
Carefully crafted isometric icons.
I found this site [yosupo judge], which is kind of similar to [cses fi].
I have solved this question there: [Deque]
I have solved this question there: [Deque]
🔥2