NAMMA_YATRI Coding Question – Solved

9 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

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |