NAMMA_YATRI Coding Question – Solved

11 Live
Directory Structure (SDE Question) - Part A You are given a directory structure represented as a tree, where each node represents a directory that can have any number of child directories. - Each child directory will have a unique name. - The second line of the input will contain the root name and its child directories. Based on the given input, you have to construct the directory structure and implement three functions: countDescendants, cutPaste, and copyPaste. Function Details: 1. countDescendants(path) - Takes one argument: directory path - Returns the number of descendants of the directory Examples: countDescendants("root") => 7 countDescendants("root/a") => 2 countDescendants("root/b") => 0 countDescendants("root/c") => 2 countDescendants("root/a/d") => 0 countDescendants("root/a/e") => 0 2. cutPaste(src, dest) - It takes two arguments: source directory and destination directory - Cuts the source directory from its parent and pastes it inside the destination directory Example: cutPaste("root/a", "root/c") 3. copyPaste(src, dest) - It takes two arguments: source directory and destination directory - Copies the source directory and pastes it into the destination Example: copyPaste("root/a","root/c") Output: - countDescendants(node): print the total number of descendants or "Invalid command" - cutPaste(src, dest): print "OK" or "Invalid command" - copyPaste(src, dest): print "OK" or "Invalid command" Negative Conditions: - If the source is an ancestor of the destination, print "Invalid command" - If source = destination, print "Invalid command" - If the destination already has a directory of the source's name, print "Invalid command" - If not a valid path for the source or destination, print "Invalid command" - If command causes total nodes > 10^6, print "Invalid command" Input Bounds: - 1 <= n <= 10^5 (structure lines) - 1 <= q <= 10^5 (commands) - Total number of nodes at any point: <= 10^6

Asked in: NAMMA_YATRI

Image of the Question

Question Image Question Image Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



No images available for this passcode.

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |