PolicyBazaar
Marvel School Interview Questions and Answers
Q1. BFS Traversal in a Graph
Given an undirected and disconnected graph G(V, E) where V vertices are numbered from 0 to V-1, and E represents edges, your task is to output the BFS traversal starting from the 0th ve...read more
BFS traversal of an undirected and disconnected graph starting from vertex 0.
Implement BFS algorithm to traverse the graph starting from vertex 0.
Use a queue to keep track of visited nodes and their neighbors.
Ensure the traversal starts from vertex 0 and follows the BFS order.
Output the BFS traversal sequence for each test case in a separate line.
Handle disconnected components by checking for unvisited nodes.
Consider the constraints for the number of vertices and edges in the...read more
Q2. DFS Traversal Problem Statement
Given an undirected and disconnected graph G(V, E)
, where V
is the number of vertices and E
is the number of edges, the connections between vertices are provided in the 'GRAPH' m...read more
DFS traversal problem to find connected components in an undirected and disconnected graph.
Use Depth First Search (DFS) algorithm to traverse the graph and find connected components
Maintain a visited array to keep track of visited vertices
Iterate through all vertices and perform DFS on unvisited vertices to find connected components
Q3. Nth Fibonacci Number Problem Statement
Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2)
, with initial conditions F(1) = F(2) = 1
.
Input:
The inp...read more
Calculate the Nth Fibonacci number efficiently using dynamic programming.
Use dynamic programming to store and reuse previously calculated Fibonacci numbers.
Start with base cases F(1) and F(2) as 1, then calculate subsequent Fibonacci numbers.
Optimize the solution to avoid redundant calculations by storing intermediate results.
Time complexity can be reduced to O(N) using dynamic programming.
Q4. Height of Binary Tree
You are provided with the Inorder and Level Order traversals of a Binary Tree composed of integers. Your goal is to determine the height of this Binary Tree without actually constructing i...read more
Find the height of a Binary Tree given its Inorder and Level Order traversals without constructing it.
Use the properties of Inorder and Level Order traversals to determine the height of the Binary Tree.
The height of a Binary Tree is the number of edges on the longest path from the root to a leaf node.
Consider edge cases like a single node tree or empty tree while calculating the height.
Q5. Right View of Binary Tree
Given a binary tree of integers, your task is to output the right view of the tree.
The right view of a binary tree includes the nodes that are visible when the tree is observed from t...read more
The task is to output the right view of a binary tree, which includes the nodes visible when observed from the right.
Perform level order traversal of the binary tree.
For each level, add the rightmost node to the result.
Print the result as the right view of the binary tree.
Handle null nodes represented by -1 in the input.
Q6. Determine the Left View of a Binary Tree
You are given a binary tree of integers. Your task is to determine the left view of the binary tree. The left view consists of nodes that are visible when the tree is vi...read more
The task is to determine the left view of a binary tree, which consists of nodes visible when viewed from the left side.
Traverse the binary tree level by level from left to right, keeping track of the first node encountered at each level.
Use a queue to perform level order traversal of the binary tree.
Store the leftmost node at each level in the result array.
Return the result array containing the left view of the binary tree.
Interview Process at Marvel School
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month