Add office photos
Employer?
Claim Account for FREE

Josh Technology Group

3.0
based on 75 Reviews
Filter interviews by

90+ MapleFly International Interview Questions and Answers

Updated 18 Sep 2024
Popular Designations

Q1. Non-Decreasing Array Problem Statement

Given an integer array ARR of size N, determine if it can be transformed into a non-decreasing array by modifying at most one element.

An array is defined as non-decreasin...read more

Ans.

The solution checks if an integer array can become non-decreasing by modifying at most one element.

  • Iterate through the array and check if there are more than one decreasing pairs of elements.

  • If there are more than one decreasing pairs, return false.

  • If there is only one decreasing pair, check if modifying one of the elements can make the array non-decreasing.

  • If modifying the element at index i-1 or i can make the array non-decreasing, return true.

  • Otherwise, return false.

View 2 more answers

Q2. Find Unique Element in Array

You have been provided an integer array/list ARR of size N. Here, N is equivalent to 2M + 1 where each test case has M numbers appearing twice and one number appearing exactly once....read more

Ans.

The task is to find the unique number in an array where all other numbers occur twice.

  • The array size is given by N = 2M + 1, where M is the number of elements occurring twice.

  • Loop through the array and use a hashmap to count the occurrences of each number.

  • Return the number with a count of 1, as it is the unique number.

View 2 more answers

Q3. Validate Binary Tree Nodes Problem

You are provided with 'N' binary tree nodes labeled from 0 to N-1, where node i has two potential children, recorded in the LEFT_CHILD[i] and RIGHT_CHILD[i] arrays. Determine ...read more

Ans.

The task is to determine if the given binary tree nodes form exactly one valid binary tree.

  • Check if there is only one root node (a node with no parent)

  • Check if each node has at most one parent

  • Check if there are no cycles in the tree

  • Check if all nodes are connected and form a single tree

Add your answer

Q4. Balanced Binary Trees Problem Statement

You are provided with an integer 'H'. Your task is to determine and print the maximum number of balanced binary trees possible with height 'H'.

A balanced binary tree is ...read more

Ans.

The maximum number of balanced binary trees possible with a given height is to be counted and printed.

  • A balanced binary tree is one in which the difference between the left and right subtree heights is less than or equal to 1.

  • The number of balanced binary trees can be calculated using dynamic programming.

  • The number of balanced binary trees with height 'H' can be obtained by summing the product of the number of balanced binary trees for each possible left and right subtree hei...read more

Add your answer
Discover MapleFly International interview dos and don'ts from real experiences

Q5. Sort Linked List Based on Actual Values

You are given a Singly Linked List of integers that is initially sorted according to the absolute values of its elements. Your task is to sort this Linked List based on t...read more

Ans.

The task is to sort a singly linked list based on actual values instead of absolute values.

  • Traverse the linked list and store the values in an array

  • Sort the array using any sorting algorithm

  • Create a new linked list using the sorted array

  • Return the new linked list

Add your answer

Q6. Wave Array Sorting Problem

Your goal is to sort a given unsorted array ARR such that it forms a wave array.

Explanation:

After sorting, the array should satisfy the wave pattern conditions:

  • ARR[0] >= ARR[1]
  • AR...read more
Ans.

The task is to sort an array in a wave form, where each element is greater than or equal to its adjacent elements.

  • Iterate through the array and swap adjacent elements if they do not follow the wave pattern

  • Start from the second element and compare it with the previous element, swap if necessary

  • Continue this process until the end of the array

  • Repeat the process for the remaining elements

  • Return the sorted wave array

Add your answer
Are these interview questions helpful?

Q7. Check If Linked List Is Palindrome

Given a singly linked list of integers, determine if the linked list is a palindrome.

Explanation:

A linked list is considered a palindrome if it reads the same forwards and b...read more

Ans.

Check if a given singly linked list of integers is a palindrome or not.

  • Create a function to reverse the linked list.

  • Use two pointers to find the middle of the linked list.

  • Compare the first half of the linked list with the reversed second half to determine if it's a palindrome.

Add your answer

Q8. Pair Sum in BST Problem Statement

Given a Binary Search Tree (BST) and a target value K, determine if there exist two unique elements in the BST such that their sum equals K.

Input:

An integer T, the number of ...read more
Ans.

The task is to check if there exist two unique elements in the given BST such that their sum is equal to the given target 'K'.

  • Traverse the BST in-order and store the elements in a sorted array

  • Use two pointers, one at the beginning and one at the end of the array

  • Check if the sum of the elements at the two pointers is equal to the target 'K'

  • If the sum is less than 'K', move the left pointer to the right

  • If the sum is greater than 'K', move the right pointer to the left

  • Repeat the...read more

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q9. Maximum Sum BST Problem Statement

You are presented with a Binary Tree 'root', which may not necessarily be a Binary Search Tree (BST). Your objective is to identify the maximum sum of node values in any subtre...read more

Ans.

The task is to find the maximum sum of node values of any subtree that is a Binary Search Tree(BST).

  • Traverse the binary tree in a bottom-up manner

  • For each node, check if it forms a BST and calculate the sum of its subtree

  • Keep track of the maximum sum encountered so far

  • Return the maximum sum

Add your answer
Q10. ...read more

Diameter of a Binary Tree Problem Statement

Given a binary tree, return the length of its diameter. The diameter of a binary tree is defined as the length of the longest path between any two nodes in the tree.

Ans.

The diameter of a binary tree is the length of the longest path between any two end nodes in the tree.

  • The diameter of a binary tree can be calculated by finding the maximum of the following three values: 1) the diameter of the left subtree, 2) the diameter of the right subtree, and 3) the longest path that passes through the root node.

  • To find the diameter of a binary tree, we can use a recursive approach. We calculate the height of the left and right subtrees, and then calcul...read more

Add your answer

Q11. Huffman Coding Challenge

Given an array ARR of integers containing 'N' elements where each element denotes the frequency of a character in a message composed of 'N' alphabets of an alien language, your task is ...read more

Ans.

Implement a function to generate Huffman codes for characters based on their frequencies in an alien language message.

  • Use a priority queue to build the Huffman tree efficiently.

  • Assign '0' and '1' to left and right branches of the tree respectively to generate unique binary codes.

  • Ensure that each code distinctly identifies its corresponding character and minimizes the total number of bits used for the message.

View 1 answer

Q12. 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

Ans.

The task is to find all nodes in a binary tree that are at a distance K from a given node.

  • Implement a function that takes the binary tree, target node, and distance K as input.

  • Use a depth-first search (DFS) algorithm to traverse the tree and find the nodes at distance K.

  • Keep track of the distance from the current node to the target node while traversing.

  • When the distance equals K, add the current node to the result list.

  • Continue the DFS traversal to explore other nodes in the...read more

Add your answer

Q13. 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

Ans.

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

View 1 answer

Q14. Railway Seat Berth Determination

Given a railway seat number represented as an integer, determine if it is a valid seat number and identify its berth type. Possible berth types include lower berth, middle berth...read more

Ans.

Given a railway seat number, determine if it is valid and identify its berth type.

  • Parse input integer 't' for number of test cases

  • For each test case, check if seat number is valid (1 <= N <= 100)

  • Identify berth type based on seat number and output the result

  • Possible berth types are Lower, Middle, Upper, Side Lower, and Side Upper

Add your answer

Q15. 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
Add your answer

Q16. 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

Add your answer

Q17. Merge K Sorted Arrays Problem Statement

Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.

Input

The f...read more
Ans.

Merge K sorted arrays into a single sorted array.

  • Create a min heap to store the first element of each array along with the array index.

  • Pop the top element from the heap, add it to the result array, and push the next element from the same array back to the heap.

  • Repeat the process until all elements are processed.

  • Time complexity: O(N log K) where N is the total number of elements and K is the number of arrays.

Add your answer

Q18. Segregate Odd-Even Problem Statement

In a wedding ceremony at NinjaLand, attendees are blindfolded. People from the bride’s side hold odd numbers, while people from the groom’s side hold even numbers. For the g...read more

Ans.

Rearrange a linked list such that odd numbers appear before even numbers while preserving the order.

  • Create two separate linked lists for odd and even numbers

  • Traverse the original list and append nodes to respective odd/even lists

  • Combine the odd and even lists while maintaining the order

  • Return the rearranged linked list

Add your answer

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

Ans.

Yes, the 0/1 Knapsack problem can be solved using dynamic programming with a space complexity of not more than O(W).

  • Use a 1D array to store the maximum value that can be stolen for each weight capacity from 0 to W.

  • Iterate through each item and update the array based on whether including the item would increase the total value.

  • The final value in the array at index W will be the maximum value that can be stolen.

Add your answer

Q20. Last Stone Weight Problem Explanation

Given a collection of stones, each having a positive integer weight, perform the following operation: On each turn, select the two heaviest stones and smash them together. ...read more

Ans.

This question is about finding the weight of the last stone after repeatedly smashing the two heaviest stones together.

  • Sort the array of stone weights in descending order.

  • Repeatedly smash the two heaviest stones until there is at most 1 stone left.

  • If there is 1 stone left, return its weight. Otherwise, return 0.

Add your answer

Q21. K Largest Elements Problem Statement

You are given an unsorted array containing 'N' integers. Your task is to find the 'K' largest elements from this array and return them in non-decreasing order.

Input:

The fi...read more
Ans.

Yes, the problem can be solved in less than O(N*log(N)) time complexity using the Quick Select algorithm.

  • Implement Quick Select algorithm to find the Kth largest element in O(N) time complexity.

  • Partition the array around a pivot element and recursively search in the left or right partition based on the position of the pivot.

  • Once you find the Kth largest element, return all elements greater than or equal to it in non-decreasing order.

Add your answer

Q22. 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

Ans.

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

Add your answer

Q23. 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

Add your answer

Q24. 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

Add your answer

Q25. Remove Duplicates Problem Statement

You are given an array of integers. The task is to remove all duplicate elements and return the array while maintaining the order in which the elements were provided.

Example...read more

Ans.

Remove duplicates from an array of integers while maintaining order.

  • Iterate through the array and add elements to a new array if they are not already present

  • Use a hash set to keep track of unique elements

  • Return the new array with unique elements in the same order as the original array

Add your answer

Q26. 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
Ans.

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.

Add your answer

Q27. Ways To Make Coin Change

Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more

Ans.

The task is to find the total number of ways to make change for a specified value using given denominations.

  • Create a dynamic programming table to store the number of ways to make change for each value up to the target value.

  • Iterate through each denomination and update the table accordingly based on the current denomination.

  • The final answer will be the value in the table at the target value.

  • Consider edge cases such as when the target value is 0 or when there are no denominatio...read more

Add your answer

Q28. Majority Element Problem Statement

Given an array/list 'ARR' consisting of 'N' integers, your task is to find the majority element in the array. If there is no majority element present, return -1.

Example:

Inpu...read more
Ans.

Find the majority element in an array, return -1 if no majority element exists.

  • Iterate through the array and keep track of the count of each element using a hashmap.

  • Check if any element's count is greater than floor(N/2) to determine the majority element.

  • Return the majority element or -1 if no majority element exists.

Add your answer

Q29. Maximize Stock Trading Profit

You are given an array prices, representing stock prices over N consecutive days. Your goal is to compute the maximum profit achievable by performing multiple transactions (i.e., b...read more

Ans.

Find maximum profit by buying and selling stocks multiple times.

  • Iterate through the array and find all increasing sequences of stock prices.

  • Calculate profit by buying at the start and selling at the end of each increasing sequence.

  • Sum up all profits to get the maximum profit achievable.

Add your answer

Q30. 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
Add your answer

Q31. Size of Largest BST in a Binary Tree

Given a binary tree with 'N' nodes, determine the size of the largest subtree that is also a Binary Search Tree (BST).

Explanation:

A Binary Search Tree (BST) is defined as ...read more

Ans.

Find the size of the largest BST subtree in a binary tree.

  • Traverse the tree in a bottom-up manner to check if each subtree is a BST.

  • Keep track of the size of the largest BST found so far.

  • Recursively check if the current subtree is a BST and update the size accordingly.

Add your answer

Q32. Unique Element In Sorted Array

Nobita wants to impress Shizuka by correctly guessing her lucky number. Shizuka provides a sorted list where every number appears twice, except for her lucky number, which appears...read more

Ans.

Find the unique element in a sorted array where all other elements appear twice.

  • Iterate through the array and XOR all elements to find the unique element.

  • Use a hash set to keep track of elements and find the unique one.

  • Sort the array and check adjacent elements to find the unique one.

Add your answer

Q33. 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

Add your answer

Q34. Is Height Balanced Binary Tree Problem Statement

Determine if the given binary tree is height-balanced. A tree is considered height-balanced when:

  1. The left subtree is balanced.
  2. The right subtree is balanced.
  3. T...read more
Add your answer

Q35. 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

Add your answer

Q36. Longest Common Subsequence Problem Statement

Given two strings STR1 and STR2, determine the length of their longest common subsequence.

A subsequence is a sequence that can be derived from another sequence by d...read more

Ans.

The problem involves finding the length of the longest common subsequence between two given strings.

  • Use dynamic programming to solve the problem efficiently.

  • Create a 2D array to store the lengths of common subsequences of substrings.

  • Iterate through the strings to fill the array and find the length of the longest common subsequence.

  • Example: For input STR1 = 'abcde' and STR2 = 'ace', the longest common subsequence is 'ace' with a length of 3.

Add your answer

Q37. Height of a Binary Tree

You are provided with an arbitrary binary tree consisting of 'N' nodes where each node is associated with a certain value. The task is to determine the height of the tree.

Explanation:

T...read more

Ans.

Calculate the height of a binary tree given its level order traversal.

  • Traverse the binary tree level by level and keep track of the height as you go down the tree.

  • Use a queue data structure to perform level order traversal efficiently.

  • The height of a binary tree is the maximum number of edges from the root to any leaf node.

  • Handle NULL nodes represented by -1 in the input.

  • Return the height of the binary tree as a single integer.

Add your answer

Q38. Number of Islands Problem Statement

You are provided with a 2-dimensional matrix having N rows and M columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more

Ans.

Count the number of islands in a 2D matrix of 1s and 0s.

  • Use Depth First Search (DFS) or Breadth First Search (BFS) to traverse the matrix and count the number of connected components.

  • Maintain a visited array to keep track of visited cells to avoid counting the same island multiple times.

  • Iterate through each cell in the matrix and if it is a land (1) and not visited, perform DFS/BFS to explore the connected land cells.

  • Increment the island count each time a new island is encoun...read more

Add your answer

Q39. 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

Ans.

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

Add your answer

Q40. Matrix Chain Multiplication Problem

Given 'N' 2-dimensional matrices and an array ARR of length N + 1, where the first N integers denote the number of rows in each matrix and the last integer represents the num...read more

Ans.

Find the minimum number of multiplication operations required to multiply a series of matrices together.

  • Use dynamic programming to solve this problem efficiently.

  • Create a 2D array to store the minimum number of operations needed to multiply matrices.

  • Iterate through different combinations of matrices to find the optimal solution.

  • Consider the dimensions of the matrices to determine the number of operations required.

  • Calculate the minimum number of operations by considering all p...read more

Add your answer

Q41. Longest Palindromic Substring Problem Statement

You are provided with a string STR of length N. The task is to find the longest palindromic substring within STR. If there are several palindromic substrings of t...read more

Ans.

Given a string, find the longest palindromic substring within it.

  • Iterate through the string and expand around each character to find palindromes

  • Keep track of the longest palindrome found so far

  • Return the longest palindromic substring

Add your answer

Q42. Matrix Symmetry Check

You are provided with a square matrix. Your task is to return true if the matrix is symmetric; otherwise, return false.

A symmetric matrix is characterized by its transpose being equal to ...read more

Ans.

Check if a square matrix is symmetric by comparing it with its transpose.

  • Iterate through the matrix and compare each element with its corresponding element in the transpose

  • If any pair of elements do not match, return false immediately

  • If all pairs match, return true at the end

Add your answer

Q43. Maximum Length Pair Chain Problem Statement

You are given 'N' pairs of integers where the first number is always smaller than the second number, i.e., in pair (a, b) -> a < b always. A pair chain is defined as ...read more

Ans.

Find the length of the longest pair chain that can be formed using the given pairs.

  • Sort the pairs based on the second element in ascending order.

  • Iterate through the sorted pairs and keep track of the maximum chain length.

  • Update the chain length if the current pair can be added to the chain.

  • Return the maximum chain length at the end.

Add your answer

Q44. 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
Add your answer

Q45. 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

Ans.

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

Add your answer

Q46. 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

Ans.

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

Add your answer

Q47. 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

Ans.

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.

Add your answer

Q48. 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

Add your answer

Q49. Course Schedule Problem Statement

You are enrolled as a student and must complete N courses, numbered from 1 to N, to earn your degree.

Some courses have prerequisites, which means that to take course i, you mu...read more

Ans.

Determine if it is feasible to complete all courses with prerequisites.

  • Create a graph representation of the courses and prerequisites.

  • Check for cycles in the graph using topological sorting.

  • If there are no cycles, all courses can be completed.

  • Example: For input N=2, prerequisites=[[1, 2]], the output is 'Yes'.

Add your answer

Q50. Inorder Successor in a Binary Tree

Given an arbitrary binary tree and a specific node within that tree, determine the inorder successor of this node.

Explanation:

The inorder successor of a node in a binary tre...read more

Ans.

Given a binary tree and a specific node, find its inorder successor in the tree.

  • Perform an inorder traversal of the binary tree to find the successor node.

  • If the given node has a right child, the successor is the leftmost node in the right subtree.

  • If the given node does not have a right child, backtrack to find the ancestor whose left child is the given node.

Add your answer

Q51. 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

Ans.

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.

Add your answer

Q52. Intersection of Linked List Problem

You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.

Your task is to determine the data...read more

Ans.

Find the node where two linked lists merge.

  • Traverse both lists to find their lengths and the difference in lengths

  • Move the pointer of the longer list by the difference

  • Move both pointers simultaneously until they meet at the merging node

Add your answer

Q53. Most Frequent Non-Banned Word Problem Statement

Given a paragraph consisting of letters in both lowercase and uppercase, spaces, and punctuation, along with a list of banned words, your task is to find the most...read more

Ans.

Find the most frequent word in a paragraph that is not in a list of banned words.

  • Split the paragraph into words and convert them to uppercase for case-insensitivity.

  • Count the frequency of each word, excluding banned words.

  • Return the word with the highest frequency in uppercase.

View 1 answer

Q54. Rotate Linked List Problem Statement

Given a linked list consisting of 'N' nodes and an integer 'K', your task is to rotate the linked list by 'K' positions in a clockwise direction.

Example:

Input:
Linked List...read more
Ans.

Rotate a linked list by K positions in a clockwise direction.

  • Traverse the linked list to find the length and the last node.

  • Connect the last node to the head to form a circular linked list.

  • Find the new head by moving (length - K) steps from the last node.

  • Break the circular list at the new head to get the rotated linked list.

Add your answer

Q55. 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

Ans.

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.

Add your answer

Q56. 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

Ans.

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.

Add your answer

Q57. 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

Ans.

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.

Add your answer

Q58. 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

Ans.

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

Add your answer

Q59. 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
Ans.

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

Add your answer

Q60. 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

Ans.

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.

Add your answer

Q61. 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

Ans.

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.

Add your answer

Q62. 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

Ans.

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.

Add your answer

Q63. 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

Ans.

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.

Add your answer

Q64. 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

Ans.

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

Add your answer

Q65. 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

Ans.

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.

Add your answer

Q66. 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

Ans.

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

Add your answer

Q67. Balanced Parentheses Combinations

Given an integer N representing the number of pairs of parentheses, find all the possible combinations of balanced parentheses using the given number of pairs.

Explanation:

Con...read more

Ans.

Generate all possible combinations of balanced parentheses for a given number of pairs.

  • Use recursion to generate all possible combinations of balanced parentheses.

  • Keep track of the number of open and close parentheses used in each combination.

  • Return the valid combinations as an array of strings.

Add your answer

Q68. 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

Ans.

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.

Add your answer

Q69. 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
Ans.

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

Add your answer

Q70. 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

Ans.

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.

Add your answer
Q71. What are higher-order functions in JavaScript?
Ans.

Higher order functions are functions that can take other functions as arguments or return functions as their results.

  • Higher order functions can be used to create more flexible and reusable code.

  • They enable functional programming paradigms.

  • Examples of higher order functions include map, filter, and reduce in JavaScript.

Add your answer
Q72. Can you describe how to design a web crawler?
Ans.

Designing a web crawler involves defining the scope, selecting a crawling strategy, implementing the crawler, handling data storage, and ensuring politeness.

  • Define the scope of the web crawler by determining the websites to crawl and the depth of the crawl.

  • Select a crawling strategy such as breadth-first or depth-first search based on the requirements.

  • Implement the web crawler using a programming language like Python or Java, utilizing libraries like Scrapy or BeautifulSoup.

  • H...read more

Add your answer
Q73. How would you design and develop a to-do list application using local storage?
Ans.

A todo list application using localstorage.

  • Use HTML, CSS, and JavaScript to create the user interface.

  • Use the localstorage API to store and retrieve todo items.

  • Implement features like adding, editing, and deleting todo items.

  • Display the list of todo items and their status.

  • Allow users to mark todo items as completed or incomplete.

Add your answer
Q74. What is hoisting in JavaScript?
Ans.

Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope.

  • Hoisting applies to both variable and function declarations.

  • Variable declarations are hoisted but not their initializations.

  • Function declarations are fully hoisted, including their definitions.

  • Hoisting can lead to unexpected behavior if not understood properly.

Add your answer
Q75. What are promises in JavaScript?
Ans.

Promises in JavaScript are objects that represent the eventual completion or failure of an asynchronous operation.

  • Promises are used to handle asynchronous operations such as fetching data from a server or reading a file.

  • They simplify the process of writing asynchronous code by providing a more structured approach.

  • Promises have three states: pending, fulfilled, or rejected.

  • They can be chained together using methods like .then() and .catch().

  • Promises help avoid callback hell an...read more

Add your answer
Q76. Design a sign-in page using only HTML and CSS.
Ans.

Design a signin page using HTML and CSS only

  • Create a form element with input fields for username and password

  • Style the form using CSS to make it visually appealing

  • Add a submit button for users to sign in

  • Consider adding error messages or validation for user input

  • Use CSS to make the page responsive for different screen sizes

Add your answer
Q77. What is memoization in JavaScript?
Ans.

Memoization is a technique in JavaScript to cache the results of expensive function calls for future use.

  • Memoization improves performance by avoiding redundant calculations

  • It is commonly used in recursive functions or functions with expensive computations

  • The cached results are stored in a data structure like an object or a map

  • Memoization can be implemented manually or using libraries like Lodash or Memoizee

Add your answer
Q78. What is the Temporal Dead Zone in JavaScript?
Ans.

Temporal Dead Zone is a behavior in JavaScript where variables are not accessible before they are declared.

  • Temporal Dead Zone occurs when accessing variables before they are declared

  • Variables in the Temporal Dead Zone cannot be accessed or assigned

  • The Temporal Dead Zone is a result of JavaScript's hoisting behavior

  • Example: accessing a variable before it is declared will throw a ReferenceError

Add your answer
Q79. What are arrow functions in JavaScript?
Ans.

Arrow functions are a concise way to write functions in JavaScript.

  • Arrow functions have a shorter syntax compared to regular functions.

  • They do not have their own 'this' value.

  • They do not have the 'arguments' object.

  • They cannot be used as constructors with the 'new' keyword.

  • They are commonly used in functional programming and with array methods like 'map' and 'filter'.

Add your answer

Q80. What is software development life cycle and which steps are following?

Ans.

Software development life cycle (SDLC) is a process used by software developers to design, develop, and test software.

  • 1. Planning: Define the project scope, requirements, and objectives.

  • 2. Analysis: Gather and analyze user requirements.

  • 3. Design: Create a detailed design of the software.

  • 4. Implementation: Develop the software based on the design.

  • 5. Testing: Test the software for bugs and issues.

  • 6. Deployment: Release the software to users.

  • 7. Maintenance: Update and maintain t...read more

Add your answer
Q81. What is the virtual DOM in JavaScript?
Ans.

Virtual DOM is a lightweight copy of the actual DOM that allows efficient updates and rendering in JavaScript frameworks.

  • Virtual DOM is a concept used in JavaScript frameworks like React.

  • It is a lightweight copy of the actual DOM tree.

  • Changes made to the virtual DOM are compared with the actual DOM to determine the minimal updates needed.

  • This helps in efficient rendering and improves performance.

  • Virtual DOM allows developers to write code as if the entire page is rendered on ...read more

Add your answer

Q82. Regression test cases for any application

Ans.

Regression test cases ensure that changes to the application do not negatively impact existing functionality.

  • Identify critical functionalities and test cases that cover them

  • Test for compatibility with different browsers and devices

  • Test for data integrity and consistency

  • Test for performance and scalability

  • Test for security vulnerabilities

  • Test for user experience and accessibility

Add your answer

Q83. Given a value find next sibling on right side of it without using global/heap variables

Ans.

Use a binary tree traversal algorithm to find the next sibling on the right side of a given value.

  • Implement an in-order traversal algorithm to traverse the binary tree

  • Keep track of the parent node and the direction of traversal to find the next sibling on the right side

  • If the given value is the right child of its parent, move up the tree until finding a node that is the left child of its parent

Add your answer
Q84. What is an IIFE (Immediately Invoked Function Expression) in JavaScript?
Ans.

IIFE stands for Immediately Invoked Function Expression. It is a JavaScript function that is executed as soon as it is defined.

  • IIFE is a way to create a function expression and immediately invoke it.

  • It helps in creating a private scope for variables and functions.

  • It is commonly used to avoid polluting the global namespace.

  • IIFE can be written using different syntaxes like using parentheses, function declaration, or arrow functions.

Add your answer
Q85. What is JSX?
Ans.

JSX is a syntax extension for JavaScript that allows you to write HTML-like code in your JavaScript files.

  • JSX stands for JavaScript XML

  • It is commonly used with React to define the structure and appearance of components

  • JSX elements are transpiled into regular JavaScript function calls

  • It allows you to write HTML-like code with JavaScript expressions embedded within curly braces

  • Example:

    Hello, {name}!

Add your answer

Q86. What is api and how it is work ?

Ans.

API stands for Application Programming Interface. It is a set of rules and protocols that allows different software applications to communicate with each other.

  • APIs define the methods and data formats that applications can use to request and exchange information.

  • APIs can be used to access services provided by other software applications, such as retrieving data from a database or sending notifications.

  • Examples of APIs include the Google Maps API, which allows developers to in...read more

Add your answer

Q87. Introduction test cases of various objects near you

Ans.

Introduction test cases for objects near me

  • Test case for testing a chair: verify stability, check for any damages, test weight capacity

  • Test case for testing a computer: check if it powers on, test functionality of keyboard and mouse, verify internet connectivity

  • Test case for testing a pen: check if it writes smoothly, test ink flow, verify if cap fits securely

Add your answer

Q88. Check if binary tree is balanced or not.

Ans.

Check if binary tree is balanced or not.

  • A balanced binary tree has the height of left and right subtrees differ by at most 1.

  • Recursively check the height of left and right subtrees and compare.

  • Use a helper function to calculate the height of a subtree.

  • Time complexity: O(nlogn) for a balanced tree, O(n^2) for a skewed tree.

Add your answer

Q89. Delete a node from a binary tree.

Ans.

Delete a node from a binary tree.

  • Find the node to be deleted

  • If the node has no children, simply delete it

  • If the node has one child, replace it with its child

  • If the node has two children, find the minimum value in its right subtree, replace the node with that value, and delete the minimum value node

Add your answer

Q90. Detect a loop in linked list

Ans.

Use Floyd's Tortoise and Hare algorithm to detect a loop in a linked list.

  • Initialize two pointers, slow and fast, at the head of the linked list.

  • Move slow pointer by one step and fast pointer by two steps.

  • If they meet at any point, there is a loop in the linked list.

Add your answer

Q91. Left view of tree

Ans.

Left view of a tree is the set of nodes visible when the tree is viewed from the left side.

  • Traverse the tree in a level order manner

  • Keep track of the first node encountered at each level

  • Add the first node encountered at each level to the result array

Add your answer

Q92. Detect loops in linked list.

Ans.

Detect loops in a linked list.

  • Use two pointers, one moving at a faster pace than the other.

  • If there is a loop, the faster pointer will eventually catch up to the slower one.

  • To detect the start of the loop, reset one pointer to the head and move both pointers at the same pace.

Add your answer

Q93. Ai tools importance in sqa

Ans.

AI tools play a crucial role in Software Quality Assurance by automating testing processes, improving efficiency, and detecting defects early.

  • AI tools can automate repetitive testing tasks, saving time and effort.

  • AI tools can analyze large amounts of data quickly and accurately, helping to identify potential defects.

  • AI tools can improve test coverage by generating test cases based on historical data and patterns.

  • AI tools can help in predicting potential issues before they occ...read more

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at MapleFly International

based on 50 interviews
Interview experience
3.8
Good
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Interview Questions from Similar Companies

4.0
 • 867 Interview Questions
3.8
 • 333 Interview Questions
4.0
 • 199 Interview Questions
3.8
 • 181 Interview Questions
3.4
 • 174 Interview Questions
3.9
 • 140 Interview Questions
View all
Top Josh Technology Group Interview Questions And Answers
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter