APIwiz Assignment
1.Complex Graph traversal :
Given a workflow represented as a directed graph with a tree-like structure (refer the below
example for reference) —where nodes may diverge (have multiple children) and converge (have
multiple parents)—each node performs a simple task: printing the node name. The input will be
provided in the form of a vertexMap, which maps node id to their node name, and an
edgeSet, which contains pairs of directed edges between nodes. The task is to construct the
directed graph from this input and achieve the below goal.
Constraints:
● A node can only be executed after all of its parent nodes have been executed.
● If a node has multiple children, they should be executed and traversed in parallel.
Goal:
Traverse the entire graph starting from the root node, ensuring each node is executed
once, respecting the constraints above.
Sample graph :
Input :
Enter the number of vertices in the first line as N. In the following N lines, provide each node’s
details. Example : "1:Node-1", where 1 is the node key and Node-1 is the node name,
separated by a colon (:). After entering the vertices,
input the number of edges as M. In the next M lines, enter each edge. Example : "1:2",
where 1 is the key of the source node and 2 is the key of the destination node. The two keys
should be separated by a colon(:).
With the input, Build a Directed graph and code the logic
Note : The starting node will always have the key 1. *
Output :
Print the names of the nodes in the order they are traversed.
On the next line, print the total number of nodes.
Example Input :
5
1:Node-1
2:Node-2
3:Node-3
4:Node-4
5:Node-5
5
1:2
1:3
2:4
2:5
3:5
Example Output :
Node-1
Node-2
Node-4
Node-3
Node-5
5
Note:
● This is not a DSA (Data Structures and Algorithms) problem; it is an
implementation-based assignment. You may also be required to use multithreading
to ensure proper execution of the workflow.
● The use of AI tools or assistance is strictly prohibited for this assignment. Any
submission found to have been generated or influenced by AI will result in immediate
disqualification.
Additional Assignment Documentation:
Executing JavaScript and Python
Scripts from Java
We encourage you to attempt the following optional assignment. While it is not mandatory,
completing it may enhance your application and help strengthen your profile during our
evaluation process. *
Objective
Develop a Java-based scripting engine utility that dynamically executes JavaScript and Python
scripts, returning their output as Java objects.
This should be done entirely within the Java Virtual Machine (JVM) without external
command-line tools (e.g., ProcessBuilder). The solution should support the use of external
libraries in both scripting languages.
Requirements
1. Create a Java method with the following signature (or similar):
Java
Object runScript(String language, String script);
2. The language parameter should support:
● "JavaScript"
● "python"
3. The script parameter should contain:
● Raw script content as a String
● (Optional enhancement: support for reading from a file)
4. The method must:
● Evaluate the script
● Return the result as a Java Object
● Support the use of libraries from JavaScript and Python
Constraints
● Must not use ProcessBuilder or similar.
● Can use any supported version of Java (Java 8 or later).
● Must allow importing and using standard and third-party libraries in both scripting
languages.
● Optional: make the method thread-safe and reusable (e.g., via a service class ).