Full Stack Developer
700+ Full Stack Developer Interview Questions and Answers
Popular Companies
Q51. Cycle Detection in Undirected Graph Problem Statement
You are provided with an undirected graph containing 'N' vertices and 'M' edges. The vertices are numbered from 1 to 'N'. Your objective is to determine whe...read more
Detect if an undirected graph contains a cycle by exploring all possible paths.
Use Depth First Search (DFS) to traverse the graph and detect cycles.
Maintain a visited set to keep track of visited vertices and a parent pointer to avoid revisiting the same vertex.
If a visited vertex is encountered that is not the parent of the current vertex, a cycle is present.
Check for cycles in each connected component of the graph.
Example: For input N=3, Edges=[[1, 2], [2, 3], [1, 3]], the ...read more
Q52. Longest Common Prefix Problem Statement
You are given an array ‘ARR’ consisting of ‘N’ strings. Your task is to find the longest common prefix among all these strings. If there is no common prefix, you have to ...read more
Find the longest common prefix among an array of strings.
Iterate through the strings character by character to find the longest common prefix
Use a loop to compare characters of all strings at the same index
Return the prefix once a character mismatch is found
Q53. Bursting Balloons Problem
Given an array ARR
of size N
, where each element represents the height of a balloon. The task is to destroy all balloons by shooting arrows from left to right. When an arrow hits a bal...read more
Find the minimum number of arrows needed to burst all balloons by shooting arrows from left to right.
Sort the array in ascending order to make it easier to determine the minimum number of arrows needed.
Iterate through the sorted array and count the number of times the height decreases.
The count of height decreases plus 1 gives the minimum number of arrows needed to burst all balloons.
Q54. Number of Islands Problem Statement
Given a non-empty grid of 0s and 1s, determine the number of distinct islands. An island is a collection of '1's (land) connected horizontally, vertically, or diagonally. It ...read more
The task is to determine the number of distinct islands in a grid of 0s and 1s connected horizontally, vertically, or diagonally.
Iterate through the grid and perform depth-first search (DFS) to find connected '1's forming islands.
Use a set to keep track of visited cells to avoid counting the same island multiple times.
Increment the island count each time a new island is encountered.
Consider edge cases such as grid boundaries and handling '0's as water.
Implement a recursive DF...read more
Q55. Print Nodes at Distance K from a Given Node
Given an arbitrary binary tree, a node of the tree, and an integer 'K', find all nodes that are at a distance K from the specified node, and return a list of these no...read more
Given a binary tree, a target node, and an integer K, find all nodes at distance K from the target node.
Traverse the binary tree to find the target node.
Use BFS to traverse the tree and find nodes at distance K from the target node.
Keep track of the distance of each node from the target node while traversing.
Return the values of nodes at distance K in any order.
Q56. Queue Using Stacks Implementation
Design a queue data structure following the FIFO (First In First Out) principle using only stack instances.
Explanation:
Your task is to complete predefined functions to suppor...read more
Implement a queue using stacks following FIFO principle.
Use two stacks to simulate a queue - one for enqueue and one for dequeue operations.
For enQueue operation, push elements onto the enqueue stack.
For deQueue operation, if the dequeue stack is empty, pop all elements from enqueue stack to dequeue stack.
For peek operation, return the top element of the dequeue stack.
For isEmpty operation, check if both stacks are empty.
Example: enQueue(5), enQueue(10), peek() -> 5, deQueue(...read more
Share interview questions and help millions of jobseekers 🌟
Q57. Rotate Matrix by 90 Degrees Problem Statement
Given a square matrix 'MATRIX' of non-negative integers, rotate the matrix by 90 degrees in an anti-clockwise direction using only constant extra space.
Input:
The ...read more
Rotate a square matrix by 90 degrees in an anti-clockwise direction using constant extra space.
Iterate through each layer of the matrix from outer to inner layers
Swap elements in groups of 4 to rotate the matrix
Handle odd-sized matrices by adjusting the center element if needed
Q58. Shortest Path in a Binary Matrix Problem Statement
Given a binary matrix of size N * M
where each element is either 0 or 1, find the shortest path from a source cell to a destination cell, consisting only of 1s...read more
Find the shortest path in a binary matrix from a source cell to a destination cell consisting only of 1s.
Use Breadth First Search (BFS) algorithm to find the shortest path.
Keep track of visited cells to avoid revisiting them.
Calculate the path length by counting the number of 1s in the path.
Handle edge cases such as invalid inputs and unreachable destination.
Full Stack Developer Jobs
Q59. Square Root with Decimal Precision Problem Statement
You are provided with two integers, 'N' and 'D'. Your objective is to determine the square root of the number 'N' with a precision up to 'D' decimal places. ...read more
Implement a function to find the square root of a number with a given precision.
Create a function that takes 'N' and 'D' as input parameters
Use a mathematical algorithm like Newton's method to approximate the square root
Iterate until the precision condition is met
Return the square root with the required precision
Q60. Factorial of a Number Problem Statement
You are provided with an integer 'N'. Your task is to calculate and print the factorial of 'N'. The factorial of a number 'N', denoted as N!, is the product of all positi...read more
Calculate and print the factorial of a given integer 'N'.
Iterate from 1 to N and multiply each number to calculate factorial
Handle edge cases like N=0 or N=1 separately
Use recursion to calculate factorial efficiently
Q61. Maximum Sum of Products for Array Rotations
You are given an array ARR
consisting of N
elements. Your task is to determine the maximum value of the summation of i * ARR[i]
among all possible rotations of ARR
. R...read more
Find the maximum sum of products for array rotations.
Iterate through all possible rotations of the array and calculate the sum of products for each rotation.
Keep track of the maximum sum of products found so far.
Return the maximum sum of products obtained.
Q62. LCA in a Binary Search Tree
You are given a binary search tree (BST) containing N nodes. Additionally, you have references to two nodes, P and Q, within this BST.
Your task is to determine the Lowest Common Anc...read more
Find the Lowest Common Ancestor (LCA) of two nodes in a Binary Search Tree (BST).
Traverse the BST from the root node to find the LCA of the given nodes.
Compare the values of the nodes with the values of P and Q to determine the LCA.
If the values of P and Q are on opposite sides of the current node, then the current node is the LCA.
Q63. Validate BST Problem Statement
Given a binary tree with N
nodes, determine whether the tree is a Binary Search Tree (BST). If it is a BST, return true
; otherwise, return false
.
A binary search tree (BST) is a b...read more
Validate if a binary tree is a Binary Search Tree (BST) based on given properties.
Check if the left subtree of a node contains only nodes with data less than the node's data.
Verify if the right subtree of a node contains only nodes with data greater than the node's data.
Ensure that both the left and right subtrees are also binary search trees.
Iterate through the tree in level order form to validate the BST properties.
Q64. House Robber Problem Statement
Mr. X is a professional robber with a plan to rob houses arranged in a circular street. Each house has a certain amount of money hidden, separated by a security system that alerts...read more
The task is to find the maximum amount of money Mr. X can rob from houses arranged in a circle without alerting the police.
The problem can be solved using dynamic programming.
Create two arrays to store the maximum amount of money robbed when considering the first house and when not considering the first house.
Iterate through the array and update the maximum amount of money robbed at each house.
The final answer will be the maximum of the last element in both arrays.
Q65. Relative Sorting Problem Statement
You are given two arrays, 'ARR' of size 'N' and 'BRR' of size 'M'. Your task is to sort the elements of 'ARR' such that their relative order matches that in 'BRR'. Any element...read more
Sort elements of ARR to match relative order in BRR, append missing elements at the end in sorted order.
Create a hashmap to store the index of elements in BRR for quick lookup.
Sort elements in ARR based on their index in BRR, append missing elements at the end.
Handle edge cases like empty arrays or duplicate elements in ARR and BRR.
Q66. Word Ladder Problem Statement
Given two strings, BEGIN
and END
, along with an array of strings DICT
, determine the length of the shortest transformation sequence from BEGIN
to END
. Each transformation involves ...read more
The Word Ladder problem involves finding the shortest transformation sequence from one word to another by changing one letter at a time.
Use breadth-first search to find the shortest transformation sequence.
Create a graph where each word is a node and words that can be transformed into each other are connected.
Keep track of visited words to avoid cycles and optimize the search process.
Return -1 if no transformation sequence is possible.
Example: For input 'hit', 'cog', and dict...read more
AVL Tree Insertion Problem
Given an AVL tree, your task is to insert an element into the AVL Tree ensuring it remains balanced.
An AVL tree is a self-balancing binary search tree with the following properties:
Insert an element into an AVL tree while maintaining balance.
Ensure the AVL tree remains balanced after insertion by performing rotations if necessary.
Update the height of each node after insertion to maintain the AVL property.
Perform single or double rotations based on the balance factor of the nodes.
Example: Inserting 7 into the AVL tree shown in the image would require a double rotation to balance the tree.
Q68. Build Max Heap Problem Statement
Given an integer array with N elements, the task is to transform this array into a max binary heap structure.
Explanation:
A max-heap is a complete binary tree where each intern...read more
The task is to transform an integer array into a max binary heap structure.
Create a max heap from the given array by rearranging elements
Ensure each internal node has a value greater than or equal to its children
Check if the transformed array represents a max-heap and output 1 if true, 0 if false
Q69. Character Counting Challenge
Create a program that counts and prints the total number of specific character types from user input. Specifically, you need to count lowercase English alphabets, numeric digits (0-...read more
Create a program that counts lowercase alphabets, digits, and white spaces from user input until '$' is encountered.
Read characters from input stream until '$' is encountered
Count lowercase alphabets, digits, and white spaces separately
Print the counts of each character type as three integers separated by spaces
Q70. Divide Two Integers Problem Statement
You are given two integers dividend
and divisor
. Your task is to divide the integers without using multiplication, division, and modular operators. Return the quotient afte...read more
Divide two integers without using multiplication, division, and modular operators, returning the floored value of the quotient.
Implement division using bit manipulation and subtraction
Handle edge cases like negative numbers and overflow
Return the floored value of the quotient
Q71. Group Anagrams Together
Given an array/list of strings STR_LIST
, group the anagrams together and return each group as a list of strings. Each group must contain strings that are anagrams of each other.
Example:...read more
Group anagrams in a list of strings together and return each group as a list of strings.
Iterate through the list of strings and sort each string alphabetically to create a key for grouping.
Use a hashmap to store the sorted string as key and the original string as value.
Return the values of the hashmap as the grouped anagrams.
Q72. Maximum Subarray Sum Problem Statement
Given an array ARR
consisting of N
integers, your goal is to determine the maximum possible sum of a non-empty contiguous subarray within this array.
Example of Subarrays:...read more
Find the maximum sum of a contiguous subarray within an array of integers.
Iterate through the array and keep track of the maximum sum of subarrays seen so far.
Use Kadane's algorithm to efficiently find the maximum subarray sum.
Consider edge cases like all negative numbers in the array.
Example: For input [-2, 1, -3, 4, -1], the maximum subarray sum is 4.
Q73. Minimum Number of Swaps to Sort an Array
Find the minimum number of swaps required to sort a given array of distinct elements in ascending order.
Input:
T (number of test cases)
For each test case:
N (size of the...read more
The minimum number of swaps required to sort a given array of distinct elements in ascending order.
Use a hashmap to store the original indices of the elements in the array.
Iterate through the array and swap elements to their correct positions.
Count the number of swaps needed to sort the array.
Q74. Rearrange String Problem Statement
Given a string ‘S’, your task is to rearrange its characters so that no two adjacent characters are the same. If it's possible, return any such arrangement, otherwise return “...read more
Given a string, rearrange its characters so that no two adjacent characters are the same. Return 'Yes' if possible, 'No' otherwise.
Iterate through the string and count the frequency of each character
Use a priority queue to rearrange characters based on frequency
Check if the rearranged string has no two adjacent characters the same
Return 'Yes' if possible, 'No' otherwise
Q75. 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
The task is to determine the maximum profit that can be achieved by performing up to two buy-and-sell transactions on a given set of stock prices.
Iterate through the array of stock prices to find the maximum profit that can be achieved by buying and selling stocks at different points.
Keep track of the maximum profit that can be achieved by considering all possible combinations of buy and sell transactions.
Ensure that you sell the stock before buying again to adhere to the con...read more
Q76. Construct Tree from Preorder Traversal
Given a list of integers pre[]
of size n
, representing the preorder traversal of a special binary tree where each node has 0 or 2 children, and a boolean array isLeaf[]
in...read more
Construct a binary tree from preorder traversal and leaf node information.
Create a binary tree using preorder traversal and leaf node information
Use recursion to build the tree
Handle both leaf and non-leaf nodes appropriately
Q77. Container with Most Water Problem Statement
Given a sequence of 'N' space-separated non-negative integers A[1], A[2], ..., A[i], ..., A[n], where each number in the sequence represents the height of a line draw...read more
Find the maximum area of water that can be contained between any two lines on a plane.
Iterate through the array of heights using two pointers approach to find the maximum area.
Calculate the area using the formula: area = (min(height[left], height[right]) * (right - left)).
Move the pointer pointing to the smaller height towards the center to potentially find a larger area.
Q78. Count Pairs with Given Sum
Given an integer array/list arr
and an integer 'Sum', determine the total number of unique pairs in the array whose elements sum up to the given 'Sum'.
Input:
The first line contains ...read more
Count the total number of unique pairs in an array whose elements sum up to a given value.
Use a hashmap to store the frequency of each element in the array.
Iterate through the array and for each element, check if (Sum - current element) exists in the hashmap.
Increment the count of pairs if the complement exists in the hashmap.
Divide the count by 2 to avoid counting duplicates like (arr[i], arr[j]) and (arr[j], arr[i]) separately.
Q79. Find Duplicate in Array Problem Statement
You are provided with an array of integers 'ARR' consisting of 'N' elements. Each integer is within the range [1, N-1], and the array contains exactly one duplicated el...read more
Find the duplicate element in an array of integers.
Iterate through the array and keep track of the frequency of each element using a hashmap.
Return the element with a frequency greater than 1 as the duplicate.
Time complexity should be O(n) and space complexity should be O(n).
Q80. Find the Longest Palindromic Substring
Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.
If there are multiple longest palindromic ...read more
Find the longest palindromic substring in a given string, returning the rightmost one if multiple exist.
Iterate through each character in the string and expand around it to find palindromes
Keep track of the longest palindrome found and its starting index
Return the substring starting from the index of the longest palindrome found
Q81. Find the Row with the Maximum Number of 1's
You are given a non-empty grid MAT
with 'N' rows and 'M' columns, where each element is either 0 or 1. All rows are sorted in ascending order.
Your task is to determi...read more
Find the row with the maximum number of 1's in a grid of 0's and 1's, returning the index of the row with the most 1's.
Iterate through each row of the grid and count the number of 1's in each row
Keep track of the row index with the maximum number of 1's seen so far
Return the index of the row with the maximum number of 1's
Q82. Kth Smallest and Largest Element Problem Statement
You are provided with an array 'Arr' containing 'N' distinct integers and a positive integer 'K'. Your task is to find the Kth smallest and Kth largest element...read more
Find the Kth smallest and largest elements in an array.
Sort the array to easily find the Kth smallest and largest elements.
Ensure K is within the array's size to avoid errors.
Handle multiple test cases efficiently.
Consider edge cases like when N is small or K is at the extremes.
Q83. Longest Duplicate Substring Problem Statement
You are provided with a string 'S'. The task is to determine the length of the longest duplicate substring within this string. Note that duplicate substrings can ov...read more
Find the length of the longest duplicate substring in a given string.
Iterate through all possible substrings of the input string.
Use a rolling hash function to efficiently compare substrings.
Store the lengths of duplicate substrings and return the maximum length.
Q84. Longest Substring Without Repeating Characters Problem Statement
Given a string S
of length L
, determine the length of the longest substring that contains no repeating characters.
Example:
Input:
"abacb"
Output...read more
Find the length of the longest substring without repeating characters in a given string.
Use a sliding window approach to keep track of the longest substring without repeating characters.
Use a hashmap to store the index of each character in the string.
Update the start index of the window when a repeating character is found.
Calculate the maximum length of the window as you iterate through the string.
Return the maximum length of the window as the result.
Q85. Problem Statement: Parity Move
You have an array of integers, and your task is to modify the array by moving all even numbers to the beginning while placing all odd numbers at the end. The order within even and...read more
Move all even numbers to the beginning and odd numbers to the end of an array.
Iterate through the array and swap even numbers to the front and odd numbers to the back.
Use two pointers, one starting from the beginning and one from the end, to achieve the desired arrangement.
Return the modified array with even numbers at the start and odd numbers at the end.
Q86. Rotting Oranges Problem Statement
You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:
- 0 - representing an empty cell
- 1 - representing a fresh orange...read more
Find the minimum time required to rot all fresh oranges in a grid.
Create a queue to store the rotten oranges and their time of rotting.
Iterate through the grid to find all rotten oranges and add them to the queue.
Simulate the rotting process by checking adjacent cells and updating their status.
Track the time taken to rot all fresh oranges and return the result.
Handle edge cases like unreachable fresh oranges or already rotten oranges.
Q87. Search in a Row-wise and Column-wise Sorted Matrix Problem Statement
You are given an N * N matrix of integers where each row and each column is sorted in increasing order. Your task is to find the position of ...read more
Given a sorted N * N matrix, find the position of a target integer 'X'.
Iterate over rows and columns to search for the target integer 'X'.
Utilize the sorted nature of the matrix to optimize the search process.
Return the position of 'X' if found, else return '-1 -1'.
Q88. Smallest Number with Given Digit Product
Given a positive integer 'N', find and return the smallest number 'M', such that the product of all the digits in 'M' is equal to 'N'. If such an 'M' is not possible or ...read more
Find the smallest number whose digits multiply to a given number N.
Iterate through possible digits to form the smallest number with product equal to N
Use a priority queue to keep track of the smallest possible number
Check constraints to ensure the number fits in a 32-bit signed integer
Q89. Subtree of Another Tree Problem Statement
Given two binary trees, T and S, determine whether S is a subtree of T. The tree S should have the same structure and node values as a subtree of T.
Explanation:
A subt...read more
Determine if one binary tree is a subtree of another binary tree based on their structure and node values.
Traverse through the main tree and check if any subtree matches the second tree
Use recursion to compare nodes of both trees
Handle edge cases like empty trees or null nodes
Check if the root node of the second tree exists in the main tree
Q90. The Skyline Problem
Compute the skyline of given rectangular buildings in a 2D city, eliminating hidden lines and forming the outer contour of the silhouette when viewed from a distance. Each building is descri...read more
Compute the skyline of given rectangular buildings in a 2D city, eliminating hidden lines and forming the outer contour of the silhouette.
Iterate through the buildings to find the critical points (start and end) of each building.
Sort the critical points based on x-coordinate and process them to find the skyline.
Merge consecutive horizontal segments of equal height in the output to ensure no duplicates.
Q91. Validate Binary Search Tree (BST)
You are given a binary tree with 'N' integer nodes. Your task is to determine whether this binary tree is a Binary Search Tree (BST).
BST Definition:
A Binary Search Tree (BST)...read more
Validate if a given binary tree is a Binary Search Tree (BST) or not.
Check if the left subtree of a node contains only nodes with data less than the node's data.
Check if the right subtree of a node contains only nodes with data greater than the node's data.
Ensure that both the left and right subtrees are also binary search trees.
Traverse the tree in an inorder manner and check if the elements are in sorted order.
Recursively check each node's value against the range of values ...read more
Q92. which programming language do you use regularly in your work?
I use multiple programming languages regularly in my work.
I use JavaScript for front-end development
I use Python for back-end development
I use SQL for database management
I use Bash for automation and scripting
I also have experience with Java and C++
Q93. Middle of a Linked List
You are given the head node of a singly linked list. Your task is to return a pointer pointing to the middle of the linked list.
If there is an odd number of elements, return the middle ...read more
Return the middle element of a singly linked list, or the one farther from the head if there are even elements.
Traverse the linked list with two pointers, one moving twice as fast as the other
When the fast pointer reaches the end, the slow pointer will be at the middle
If there are even elements, return the one pointed by the slow pointer
Q94. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Find pairs of elements in an array that sum up to a given value, sorted in a specific order.
Iterate through the array and use a hashmap to store the difference between the target sum and each element.
Check if the difference exists in the hashmap, if so, add the pair to the result list.
Sort the result list based on the criteria mentioned in the problem statement.
Q95. Vertical Order Traversal Problem Statement
You are given a binary tree, and the task is to perform a vertical order traversal of the values of the nodes in the tree.
For a node at position ('X', 'Y'), the posit...read more
Perform vertical order traversal of a binary tree based on decreasing 'Y' coordinates.
Traverse the binary tree level by level and maintain the position of each node
Use a map to store nodes at each position and sort them based on 'Y' coordinates
Print the nodes in sorted order for each position to get the vertical order traversal
Q96. Change Start Node Problem Statement
You are provided with a singly linked list and an integer K
. The objective is to make the Kth
node from the end of the linked list the starting node of the linked list.
Input...read more
Modify a singly linked list to make the Kth node from the end the starting node.
Traverse the linked list to find the length and the Kth node from the end
Update the pointers to make the Kth node the new head of the linked list
Adjust the pointers to maintain the integrity of the linked list
Q97. Delete Node in Binary Search Tree Problem Statement
You are provided with a Binary Search Tree (BST) containing 'N' nodes with integer data. Your task is to remove a given node from this BST.
A BST is a binary ...read more
Implement a function to delete a node from a Binary Search Tree and return the inorder traversal of the modified BST.
Understand the properties of a Binary Search Tree (BST) - left subtree contains nodes with data less than the node, right subtree contains nodes with data greater than the node.
Implement a function to delete the given node from the BST while maintaining the BST properties.
Perform inorder traversal of the modified BST to get the desired output.
Handle cases where...read more
Q98. Minimum Time Problem Statement
In a city with ‘N’ junctions and ‘M’ bi-directional roads, each junction is connected to other junctions with specified travel times. No road connects a junction to itself, and on...read more
The problem involves finding the minimum time to travel from a source junction to a destination junction in a city with specified travel times and green light periods.
Input consists of the number of test cases, number of junctions and roads, green light periods, road connections with travel times, and source/destination junctions.
Output should be the minimum time needed from source to destination, or -1 if destination is unreachable.
Constraints include limits on test cases, j...read more
Q99. Prerequisite Task Completion Verification
Given a positive integer 'N', representing the number of tasks, and a list of dependency pairs, determine if it is possible to complete all tasks considering these prer...read more
Determine if it is possible to complete all tasks considering prerequisites.
Create a graph representation of the tasks and dependencies.
Use topological sorting to check if there is a cycle in the graph.
Return 'Yes' if no cycle is found, 'No' otherwise.
Q100. Root to Leaf Path Problem Statement
Given a binary tree with 'N' nodes numbered from 1 to 'N', your task is to print all the root-to-leaf paths of the binary tree.
Input:
The first line of the input contains a ...read more
Given a binary tree, print all root-to-leaf paths in order.
Traverse the binary tree from root to leaf nodes, keeping track of the path nodes.
Use depth-first search (DFS) to explore all possible paths.
Return each path as a string of nodes separated by spaces.
Handle cases where nodes have NULL values by skipping them in the path.
Ensure the order of nodes in each path is maintained.
Interview Questions of Similar Designations
Top Interview Questions for Full Stack Developer Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month