
Josh Technology Group

30+ Josh Technology Group Software Developer Intern Interview Questions and Answers
Q1. Multiply Linked Lists Problem Statement
Your task is to multiply two numbers represented as linked lists and return the resultant multiplied linked list.
Explanation:
The multiplied list should be a linked list...read more
Multiply two numbers represented as linked lists and return the resultant multiplied linked list.
Create a function that takes two linked lists as input and returns the product as a linked list
Traverse both linked lists to extract the numbers, multiply them, and create a new linked list for the product
Handle carry over while multiplying digits and adding to the result linked list
Q2. Longest Alternating Subsequence Problem
Given an array ARR
of integers, determine the length of the longest alternating subsequence.
Input:
ARR = {Array elements}
Output:
Length of the longest alternating subse...read more
Q3. Buy and Sell Stock Problem Statement
Imagine you are Harshad Mehta's friend, and you have been given the stock prices of a particular company for the next 'N' days. You can perform up to two buy-and-sell transa...read more
Q4. Add Two Numbers Represented by Linked Lists
Your task is to find the sum list of two numbers represented by linked lists and return the head of the sum list.
Explanation:
The sum list should be a linked list re...read more
Add two numbers represented by linked lists and return the head of the sum list.
Traverse both linked lists simultaneously while keeping track of carry from previous sum
Create a new linked list to store the sum of the two numbers
Handle cases where one linked list is longer than the other by padding with zeros
Update the sum and carry values accordingly while iterating through the linked lists
Q5. Closest Leaf in a Binary Tree
Ninja is stuck in a maze represented as a binary tree, and he is at a specific node ‘X’. Help Ninja find the shortest path to the nearest leaf node, which is considered an exit poi...read more
Q6. Minimum Jumps Problem Statement
Bob and his wife are in the famous 'Arcade' mall in the city of Berland. This mall has a unique way of moving between shops using trampolines. Each shop is laid out in a straight...read more
Q7. Spiral Matrix Problem Statement
Given a two-dimensional matrix of integers, print the matrix in a spiral order.
Input:
The first line contains an integer 't' indicating the number of test cases. For each test c...read more
Print a two-dimensional matrix in spiral order.
Iterate through the matrix in a spiral order by keeping track of the boundaries.
Print elements in the order: top row, right column, bottom row, left column.
Repeat the process for inner submatrices until all elements are printed.
Q8. Maximum Non-Adjacent Subsequence Sum
Given an array of integers, determine the maximum sum of a subsequence without choosing adjacent elements in the original array.
Input:
The first line consists of an integer...read more
Q9. Sum Root to Leaf Numbers
You are given an arbitrary binary tree consisting of N nodes, each associated with an integer value from 1 to 9. Each root-to-leaf path can be considered a number formed by concatenatin...read more
Q10. Is Height Balanced Binary Tree Problem Statement
Determine if the given binary tree is height-balanced. A tree is considered height-balanced when:
- The left subtree is balanced.
- The right subtree is balanced.
- T...read more
Q11. N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the...read more
Q12. Rearrange Linked List Problem Statement
Given a singly linked list in the form 'L1' -> 'L2' -> 'L3' -> ... 'Ln', your task is to rearrange the nodes to the form 'L1' -> 'Ln' -> 'L2' -> 'Ln-1', etc. You must not...read more
Rearrange the nodes of a singly linked list in a specific order without altering the data of the nodes.
Use two pointers to split the linked list into two halves, reverse the second half, and then merge the two halves alternately.
Ensure to handle cases where the number of nodes is odd or even separately.
Keep track of the head and tail of each half to properly rearrange the nodes.
Ensure to update the next pointers of the nodes correctly to rearrange the linked list in the desir...read more
Q13. Rotate Matrix K Times Problem Statement
Given a matrix, rotate its elements clockwise by 90 degrees, K times.
Each rotation by 90 degrees counts as one.
Input:
Line 1: Two integers M and N, denoting the number ...read more
Q14. Remove BST Keys Outside Given Range
Given a Binary Search Tree (BST) and a specified range [min, max], your task is to remove all keys from the BST that fall outside this range. The BST should remain valid afte...read more
Q15. Reverse Linked List in K-Groups
Given a linked list consisting of 'N' nodes and an integer 'K', reverse the linked list in groups of size K. Specifically, reverse the nodes in each group starting from (1, K), (...read more
Reverse a linked list in groups of size K
Iterate through the linked list in groups of size K
Reverse each group of nodes
Handle cases where the last group has fewer nodes than K
Q16. Merge Two Binary Trees Problem Statement
You are given the roots of two binary trees, root1
and root2
. Merge these two trees into a new binary tree. If two nodes overlap, sum the node values as the new node val...read more
Merge two binary trees by summing overlapping nodes and retaining non-null nodes.
Traverse both trees simultaneously in preorder fashion
If both nodes are not null, sum their values for the new node
If one node is null, use the non-null node as the new node
Recursively merge the left and right subtrees
Q17. Covid Vaccination Distribution Problem
As the Government ramps up vaccination drives to combat the second wave of Covid-19, you are tasked with helping plan an effective vaccination schedule. Your goal is to ma...read more
Maximize vaccines administered on a specific day while following certain rules.
Distribute vaccines evenly over the given number of days.
Ensure the difference in vaccines administered between consecutive days is at most 1.
Maximize the number of vaccines administered on the specified day.
Keep track of the total number of vaccines administered to not exceed the maximum limit.
Implement a function to calculate the maximum number of vaccines administered on the specified day.
Q18. Zig-Zag Array Rearrangement
You are provided with an array of distinct elements, and your task is to rearrange the array elements in a zig-zag manner. Specifically, for every odd index i
, the element ARR[i]
sho...read more
Rearrange array elements in a zig-zag manner where every odd index element is greater than its neighbors.
Iterate through the array and swap elements at odd indices to satisfy the zig-zag condition.
Ensure that the swapped elements are greater than their neighbors.
Multiple correct zig-zag rearrangements may exist for a given array.
Q19. 0/1 Knapsack Problem Statement
A thief is planning to rob a store and can carry a maximum weight of 'W' in his knapsack. The store contains 'N' items where the ith item has a weight of 'wi' and a value of 'vi'....read more
Yes, the 0/1 Knapsack problem can be solved using a space complexity of not more than O(W) using dynamic programming.
Use a 1D array to store the maximum value that can be stolen for each weight from 0 to W.
Iterate through the items and update the array based on the current item's weight and value.
The final value in the array will be the maximum value that can be stolen within the weight capacity of the knapsack.
Q20. Find Nodes at Distance K in a Binary Tree
Your task is to find all nodes that are exactly a distance K from a given node in an arbitrary binary tree. The distance is defined as the number of edges between nodes...read more
Find nodes at distance K from a given node in a binary tree.
Perform a depth-first search starting from the target node to find nodes at distance K.
Use a recursive function to traverse the tree and keep track of the distance from the target node.
Maintain a set to store visited nodes and avoid revisiting them.
Return the list of nodes found at distance K from the target node.
Example: If the target node is 5 and K is 2, the output should be [7, 4, 0, 8].
Q21. Nuts and Bolts Problem
You are given a collection of 'N' nuts and 'N' bolts, each having unique sizes. Your objective is to match each nut with its corresponding bolt based on size, adhering to a one-to-one map...read more
Matching nuts and bolts based on size in a one-to-one mapping strategy.
Iterate through the nuts and bolts arrays to find matching pairs based on size.
Use sorting algorithms like quicksort to efficiently match nuts and bolts.
Ensure the implementation modifies the input arrays directly to reflect the proper matched order.
Q22. Divide Chocolates Problem Statement
Ninja bought chocolate consisting of several chunks, and the sweetness of each chunk is represented in an array ARR
. He wants to divide the chocolate into K + 1
parts (cuts),...read more
The task is to maximize the total sweetness of the part that Ninja will get by dividing chocolates into K + 1 parts.
Iterate through the array of sweetness values to find the maximum sweetness value.
Use binary search to find the maximum sweetness that Ninja can obtain by making cuts.
Consider the constraints while implementing the solution.
Handle multiple test cases efficiently.
Q23. Dijkstra's Shortest Path Problem Statement
You are given an undirected graph with V
vertices (numbered from 0 to V-1) and E
edges. Each edge connects two nodes u
and v
and has an associated weight representing ...read more
Dijkstra's algorithm is used to find the shortest path distance from a source node to all vertices in an undirected graph.
Implement Dijkstra's algorithm to calculate shortest path distances
Use a priority queue to efficiently select the next node to visit
Initialize distances to all nodes as infinity, except for the source node as 0
Update distances based on the weights of edges and choose the shortest path
Handle disconnected nodes by assigning a maximum positive integer value
Q24. Sum Root to Leaf Path Problem
You are given an arbitrary binary tree consisting of N
nodes where each node is associated with an integer value from 1 to 9. Each root-to-leaf path in the tree represents a number...read more
Calculate the total sum of all possible root-to-leaf paths in a binary tree.
Traverse the tree from root to leaf nodes, keeping track of the current path sum.
Add the path sum to the total sum when reaching a leaf node.
Use recursion to explore all possible paths in the tree.
Return the total sum modulo (10^9 + 7) as the final result.
Q25. Reverse Linked List Problem Statement
Given a singly linked list of integers, return the head of the reversed linked list.
Example:
Initial linked list: 1 -> 2 -> 3 -> 4 -> NULL
Reversed linked list: 4 -> 3 -> 2...read more
Reverse a singly linked list of integers and return the head of the reversed linked list.
Iterate through the linked list and reverse the pointers to reverse the list
Use three pointers to keep track of current, previous, and next nodes
Update the head of the reversed linked list once the reversal is complete
Q26. Flatten Binary Tree to Linked List
Transform a binary tree with integer values into a linked list by ensuring the linked list's nodes follow the pre-order traversal order of the binary tree.
Explanation:
Utiliz...read more
Flatten a binary tree into a linked list following pre-order traversal order.
Use the binary tree's right pointer as the linked list's 'next' pointer.
Set each node's left pointer to NULL.
Implement the solution without printing within the function.
Follow pre-order traversal to flatten the binary tree into a linked list.
Q27. Binary Tree Diameter Problem Statement
Given a binary tree, determine the length of its diameter. The diameter is defined as the longest path between any two end nodes in the tree. The path's length is represen...read more
The diameter of a binary tree is the longest path between any two end nodes in the tree.
Traverse the tree to find the longest path between two leaf nodes.
Use depth-first search (DFS) to calculate the height of each subtree.
The diameter of the tree is the maximum of the sum of heights of left and right subtrees + 1.
Q28. Dijkstra's Shortest Path Problem
Given an undirected graph with ‘V’ vertices (labeled 0, 1, ... , V-1) and ‘E’ edges, where each edge has a weight representing the distance between two connected nodes (X, Y).
Y...read more
Dijkstra's algorithm is used to find the shortest path from a source node to all other nodes in a graph with weighted edges.
Implement Dijkstra's algorithm to find the shortest path distances from the source node to all other nodes.
Use a priority queue to efficiently select the next node with the shortest distance.
Initialize distances to all nodes as infinity except for the source node which is 0.
Update distances to neighboring nodes if a shorter path is found.
Repeat the proce...read more
Q29. Spiral Matrix Path Problem Statement
Given a N x M matrix of integers, print the spiral order of the matrix.
Input:
The input starts with an integer 'T' representing the number of test cases. Each test case con...read more
The problem involves printing the spiral order of a given matrix of integers.
Iterate through the matrix in a spiral order by keeping track of the boundaries.
Print the elements in the order: top row, right column, bottom row, left column.
Continue this process until all elements are printed in spiral order.
Q30. Equilibrium Indices in a Sequence
You are given an array/list named 'SEQUENCE', which consists of 'N' integers. The task is to identify all equilibrium indices in this sequence.
Explanation:
An equilibrium inde...read more
Identify equilibrium indices in a given sequence by finding positions where sum of elements before and after is equal.
Iterate through the sequence and calculate prefix sum and suffix sum at each index
Compare prefix sum and suffix sum to find equilibrium indices
Handle edge cases where no equilibrium index exists
Return the indices as a sequence of integers or an empty sequence
Q31. Reverse Linked List in Groups of K
You are provided with a linked list containing 'N' nodes and an integer 'K'. The task is to reverse the linked list in groups of size K, which means reversing the nodes in eac...read more
Reverse a linked list in groups of size K.
Iterate through the linked list in groups of size K.
Reverse each group of nodes.
Handle cases where the number of elements in the last group is less than K.
Q32. Nodes at Distance K from a Given Node
Given an arbitrary binary tree, a specified node within the tree, and an integer 'K', find all nodes that are exactly 'K' distance away from the specified node. Return a li...read more
Find all nodes at a specified distance K from a given node in a binary tree.
Traverse the binary tree to find the target node.
Use depth-first search to explore nodes at distance K from the target node.
Keep track of the distance from the target node while traversing.
Return a list of node values at distance K from the target node.
Handle cases where no nodes are found at the specified distance.
Q33. Replace with Sum of Greater Nodes Problem Statement
Convert a given binary search tree (BST) with 'N' nodes into a Greater Tree. In the Greater Tree, each node's data should be updated to the sum of its origina...read more
Convert a binary search tree into a Greater Tree by updating each node's data to the sum of its original data plus the data of all nodes with greater or equal values.
Traverse the BST in reverse inorder (right, root, left) to update nodes with the sum of greater nodes.
Keep track of the sum of greater nodes encountered so far while traversing.
Update each node's data with the sum of greater nodes and continue traversal.
Q34. Binary Tree Level Order Traversal
You are given a binary tree of integers. Your task is to return the level order traversal of the given tree.
Input:
The first line contains an integer 'T', representing the num...read more
Return the level order traversal of a binary tree given in level order.
Use a queue to perform level order traversal of the binary tree
Start by pushing the root node into the queue
While the queue is not empty, dequeue a node, print its value, and enqueue its children
Q35. Kth Ancestor in a Binary Tree
You are given an arbitrary binary tree consisting of N
nodes numbered from 1 to N
, an integer K
, and a node TARGET_NODE_VAL
from the tree. Your task is to find the Kth ancestor of ...read more
Find the Kth ancestor of a given node in a binary tree.
Traverse the tree to find the path from the target node to the root node.
Store the path in a list and return the Kth element from the end.
Handle cases where the Kth ancestor does not exist by returning -1.
Interview Process at Josh Technology Group Software Developer Intern

Top Software Developer Intern Interview Questions from Similar Companies







Reviews
Interviews
Salaries
Users/Month

