Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
import sys
sys.setrecursionlimit(1_000_000)
class DirNode:
def __init__(self, name):
self.name = name
self.children = {}
self.parent = None
class DirectoryTree:
def __init__(self):
self.root = DirNode("root")
self.total_nodes = 1
self.MAX_NODES = 10**6
self.path_map = {"root": self.root}
def get_node(self, path):
return self.path_map.get(path, None)
def build_path(self, parent_path, child_name):
return parent_path + "/" + child_name
def add_node(self, parent_path, *child_names):
parent = self.get_node(parent_path)
if not parent:
return
for name in child_names:
if name not in parent.children:
new_node = DirNode(name)
new_node.parent = parent
parent.children[name] = new_node
full_path = self.build_path(parent_path, name)
self.path_map[full_path] = new_node
self.total_nodes += 1
def count_descendants(self, path):
node = self.get_node(path)
if not node:
print("Invalid command")
return
def dfs(n):
count = 0
for cname, ch in n.children.items():
count += 1 + dfs(ch)
return count
print(dfs(node))
def cut_paste(self, src_path, dst_path):
src = self.get_node(src_path)
dst = self.get_node(dst_path)
if not src or not dst or src is self.root or src.name in dst.children:
print("Invalid command")
return
# Remove old paths
def remove_paths(n, current_path):
self.path_map.pop(current_path, None)
for cname, ch in n.children.items():
remove_paths(ch, self.build_path(current_path, cname))
remove_paths(src, src_path)
# Detach from old parent
del src.parent.children[src.name]
# Attach to new parent
src.parent = dst
dst.children[src.name] = src
# Add new paths
def add_paths(n, current_path):
self.path_map[current_path] = n
for cname, ch in n.children.items():
add_paths(ch, self.build_path(current_path, cname))
new_path = self.build_path(dst_path, src.name)
add_paths(src, new_path)
print("OK")
def copy_paste(self, src_path, dst_path):
src = self.get_node(src_path)
dst = self.get_node(dst_path)
if not src or not dst or src.name in dst.children:
print("Invalid command")
return
# Count number of nodes to be added
def count_nodes(n):
cnt = 1
for ch in n.children.values():
cnt += count_nodes(ch)
return cnt
needed = count_nodes(src)
if self.total_nodes + needed > self.MAX_NODES:
print("Invalid command")
return
# Clone subtree
def clone(n):
copy = DirNode(n.name)
for cname, ch in n.children.items():
child_copy = clone(ch)
child_copy.parent = copy
copy.children[cname] = child_copy
return copy
new_subtree = clone(src)
new_subtree.parent = dst
dst.children[new_subtree.name] = new_subtree
# Add new paths to map
def add_paths(n, current_path):
self.path_map[current_path] = n
for cname, ch in n.children.items():
add_paths(ch, self.build_path(current_path, cname))
new_path = self.build_path(dst_path, src.name)
add_paths(new_subtree, new_path)
self.total_nodes += needed
print("OK")
Part -1
👍3
# Input handling
def main():
n, q = map(int, input().split())
tree = DirectoryTree()
for _ in range(n):
parts = input().split()
parent = parts[0]
children = parts[1:]
tree.add_node(parent, *children)
for _ in range(q):
parts = input().split()
cmd = parts[0]
if cmd == "countDescendants":
tree.count_descendants(parts[1])
elif cmd == "cutPaste":
tree.cut_paste(parts[1], parts[2])
elif cmd == "copyPaste":
tree.copy_paste(parts[1], parts[2])
if __name__ == "__main__":
main()
Part - 2
Namma yatri - 2
Please open Telegram to view this post
VIEW IN TELEGRAM
👍1
Successfully cleared NetApp ✔️
Test accomplished
Prev Help:
https://t.me/code_alphix/6137?single
DM for help
@Mrtrueliving_ix ° @Mrtrueliving_ix
💯 Success Rate & Test clearance 👌
Test accomplished
Prev Help:
https://t.me/code_alphix/6137?single
DM for help
@Mrtrueliving_ix ° @Mrtrueliving_ix
💯 Success Rate & Test clearance 👌
Please open Telegram to view this post
VIEW IN TELEGRAM
👍1
All placement help available
- Cognizant
- Dtcc
- payU
- namma yatri
- wells forgo
- IBM - communication
- Deshaw
- innofied
- IBM - offline
- Flipkart
On // off campus placement
DM For help
@Mrtrueliving_ix
@Mrtrueliving_ix
Test clearance guarantee💯
High success rate🎉
- Cognizant
- Dtcc
- payU
- namma yatri
- wells forgo
- IBM - communication
- Deshaw
- innofied
- IBM - offline
- Flipkart
On // off campus placement
DM For help
@Mrtrueliving_ix
@Mrtrueliving_ix
Test clearance guarantee
High success rate
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Cognizant Aptitude Help done ✅
12 PM || 2/2 Slots💻
DM for help @Mrtrueliving_ix💯
#Cts #Aptitude #R2 #Offcampus
Test accomplished🩷 ⭐️
12 PM || 2/2 Slots
DM for help @Mrtrueliving_ix
#Cts #Aptitude #R2 #Offcampus
Test accomplished
All placement help available
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥1🫡1
DTCC FREE CODING POSTED
STAY TUNED
https://t.me/code_alphix
Share with your friends too
Subscribers target: 2.2k🎉
Keep sharing with friends....
Without sharing we can't post 📯
STAY TUNED
https://t.me/code_alphix
Share with your friends too
Subscribers target: 2.2k
Keep sharing with friends....
Without sharing we can't post 📯
Please open Telegram to view this post
VIEW IN TELEGRAM
👍5🔥1
Please open Telegram to view this post
VIEW IN TELEGRAM
Successfully cleared Accolite....
Test accomplished 🪄
#Accolite #shortlist
Review proof
https://t.me/code_alphix/6168
DM FOR Any Help
@Mrtrueliving_ix
@Mrtrueliving_ix
Test accomplished 🪄
#Accolite #shortlist
Review proof
https://t.me/code_alphix/6168
DM FOR Any Help
@Mrtrueliving_ix
@Mrtrueliving_ix
Cognizant Aptitude Help done ✅
4 PM || 1 Slot💻
DM for help @Mrtrueliving_ix💯
#Cts #Aptitude #R2 #Offcampus
Test accomplished🩷 ⭐️
4 PM || 1 Slot
DM for help @Mrtrueliving_ix
#Cts #Aptitude #R2 #Offcampus
Test accomplished
All placement help available
Please open Telegram to view this post
VIEW IN TELEGRAM
👍1