Software Developer
7000+ Software Developer Interview Questions and Answers
Popular Companies
Q51. Rahul And Minimum Subarray Problem Statement
Rahul is mastering arrays. He is tasked to find the length of the smallest contiguous subarray in a given array/list ARR
of size N
, such that its sum exceeds a speci...read more
Find the length of the smallest subarray in a given array whose sum exceeds a specified value.
Iterate through the array while keeping track of the sum of the current subarray.
Use two pointers to maintain a sliding window approach to find the smallest subarray.
Update the minimum length of the subarray whenever the sum exceeds the specified value.
Return the length of the smallest subarray found.
Handle cases where no subarray exists with sum exceeding the specified value.
Q52. 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
The task is to find the total number of ways to make change for a specified value using given denominations.
Use dynamic programming to solve this problem efficiently.
Create a 1D array to store the number of ways to make change for each value from 0 to the target value.
Iterate through the denominations and update the array based on the current denomination.
The final answer will be the value at the target index of the array.
Q53. Saving Money Problem Statement
Ninja is adventurous and loves traveling while being mindful of his expenses. Given a set of 'N' stations connected by 'M' trains, each train starting from station 'A' and reachin...read more
The task is to find the cheapest price from the given source to destination with up to K stops.
Read the number of test cases
For each test case, read the number of stations and trains
Read the details of each train (source, destination, ticket price)
Read the source station, destination station, and maximum number of stops
Implement a graph data structure to represent the stations and trains
Use a modified version of Dijkstra's algorithm to find the cheapest price with up to K sto...read more
Q54. Linear Search Problem Statement
Given a random integer array/list ARR
of size N
, and an integer X
, you are required to search for the integer X
in the given array/list using Linear Search.
Return the index at w...read more
Linear search algorithm to find the first occurrence of an integer in an array.
Iterate through the array and compare each element with the target integer.
Return the index if the target integer is found, else return -1.
Time complexity is O(N) where N is the size of the array.
Q55. Longest Increasing Path in a 2D Matrix Problem Statement
Given a matrix of non-negative integers of size 'N x M', where 'N' and 'M' denote the number of rows and columns respectively, find the length of the lon...read more
The task is to find the length of the longest increasing path in a 2D matrix, where you can move in four directions: left, right, up, or down from each cell.
Traverse the matrix and for each cell, find the longest increasing path starting from that cell
Use dynamic programming to store the length of the longest increasing path for each cell
Recursively explore all four directions from each cell, checking if the next cell is greater than the current cell
Keep track of the maximum ...read more
Q56. 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 point to the previous node instead of the next node.
Use three pointers to keep track of the current, previous, and next nodes while reversing the linked list.
Update the head of the reversed linked list as the last node encountered during the reversal process.
Share interview questions and help millions of jobseekers 🌟
Q57. Reverse String Word Wise Problem Statement
Your task is to reverse the given string word-wise. This means the last word in the string should appear first, the second last word should appear second, and so forth...read more
The given string needs to be reversed word wise, keeping the individual words intact.
Split the string into an array of words using a space as the delimiter.
Reverse the array of words.
Join the reversed array of words using a space as the separator to form the final reversed string.
Q58. 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
This question asks to find the position of a target integer in a row-wise and column-wise sorted matrix.
Iterate through each row and column of the matrix
Compare the target integer with the current element
If the target integer is found, return the position as {i, j}
If the target integer is not found, return {-1, -1}
Software Developer Jobs
Q59. Chocolate Distribution Problem
You are given an array/list CHOCOLATES
of size 'N', where each element represents the number of chocolates in a packet. Your task is to distribute these chocolates among 'M' stude...read more
Distribute chocolates among students to minimize the difference between the largest and smallest number of chocolates.
Sort the array of chocolates.
Use sliding window technique to find the minimum difference between the chocolates distributed to students.
Return the minimum difference as the output.
Q60. Count Good Subsets Problem Statement
Given an array ARR
of size N
consisting of distinct elements, your task is to determine the total number of good subsets. A subset is considered a good subset if the element...read more
Count the total number of good subsets in an array where elements can be rearranged to divide the next element.
Iterate through all possible subsets of the array.
Check if each subset is a good subset by rearranging elements to divide the next element.
Count the number of good subsets and return the total count.
Q61. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Given an array of integers and a target, find all pairs of elements that add up to the target.
Iterate through the array and for each element, check if the target minus the element exists in a hash set.
If it exists, add the pair to the result. If not, add the element to the hash set.
Handle cases where the same element is used twice to form a pair.
Return (-1, -1) if no pair is found.
Q62. Hurdle Game Problem Statement
Kevin is playing a hurdle game where he must jump over hurdles to clear levels. Each level ‘i’ consists of ‘i’ hurdles (e.g., Level 6 has 6 hurdles).
Given the total number of hurd...read more
The task is to determine the number of levels cleared by Kevin based on the total number of hurdles he has jumped.
Each level 'i' has 'i' hurdles, so Kevin can only reach level 'i' if he has cleared level 'i-1'.
Count the number of levels cleared by dividing the total number of hurdles by the sum of the first 'n' natural numbers.
The formula to calculate the sum of the first 'n' natural numbers is (n * (n + 1)) / 2.
Q63. N-th Fibonacci Number Problem Statement
Given an integer ‘N’, your task is to find and return the N’th Fibonacci number using matrix exponentiation.
Since the answer can be very large, return the answer modulo ...read more
The task is to find the Nth Fibonacci number using matrix exponentiation.
Use matrix exponentiation to efficiently calculate the Nth Fibonacci number
Return the answer modulo 10^9 + 7 to handle large numbers
Implement the function to solve the problem
The Fibonacci sequence starts with 1, 1, so F(1) = F(2) = 1
The time complexity can be improved to better than O(N) using matrix exponentiation
Q64. Tower Building Problem Statement
Given an array 'ARR' of 'N' cubes, you need to construct towers such that each cube can either be placed on top of an existing tower or start a new one. The restriction is that ...read more
The task is to determine the minimum number of towers needed to stack cubes in a specific order.
Iterate through the array of cubes and maintain a stack to keep track of towers.
For each cube, check if it can be placed on an existing tower or start a new one.
Update the stack based on the cube's size and count the number of towers needed.
Return the minimum number of towers required.
Example: For input N = 3, ARR = [3, 2, 1], the output should be 1.
Q65. Biggest Number Formation Problem
Your task is to construct the largest number possible by concatenating each of the provided positive integers in the array exactly once.
Input:
Integer T denoting the number of ...read more
Construct the largest number by concatenating positive integers in the array exactly once.
Sort the array of integers in a way that the concatenation of the numbers forms the largest possible number.
Use a custom comparator function to sort the numbers based on their concatenated values.
Join the sorted array elements to form the final largest number.
Q66. Digit Count In Range Problem Statement
Given an integer K
, and two numbers A
and B
, count the occurrences of the digit K
in the range [A, B].
Include both the lower and upper limits in the count.
Input:
The fir...read more
Count occurrences of a digit in a given range.
Iterate through the range [A, B] and count occurrences of digit K.
Convert integers to strings for easier digit comparison.
Handle edge cases like when A or B is equal to K.
Optimize by considering the position of K in the range.
Q67. Maximum Frequency Number Problem Statement
Given an array of integers with numbers in random order, write a program to find and return the number which appears the most frequently in the array.
If multiple elem...read more
Q68. Ninja Competition Problem Statement
Ninja is organizing a coding competition where two teams compete at a time. To keep it fair and interesting, both teams must have an equal number of members. Ninja’s task is ...read more
Check if Ninja can create two teams with equal members given an integer N and its divisors.
Iterate through all divisors of N and assign members to the first or second team based on whether the divisor is even or odd.
Keep track of the total members in each team and check if they are equal at the end.
Return true if the total members in both teams are equal, false otherwise.
Q69. Painter's Partition Problem Statement
Given an array/list representing boards, where each element denotes the length of a board, and a number ‘K’ of available painters, determine the minimum time required to pa...read more
Determine the minimum time required to paint all boards with given constraints.
Use binary search to find the minimum and maximum possible time to paint all boards.
Iterate through the boards and assign them to painters based on the time constraints.
Calculate the total time taken to paint all boards with the assigned painters.
Q70. Remove Duplicates from String Problem Statement
You are provided a string STR
of length N
, consisting solely of lowercase English letters.
Your task is to remove all duplicate occurrences of characters in the s...read more
Remove duplicate occurrences of characters in a given string of lowercase English letters.
Use a hash set to keep track of characters already seen.
Iterate through the string and add each character to the result if it's not in the hash set.
Return the result string after removing duplicates.
Q71. 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 adjacent to rotten oranges.
Create a queue to store the coordinates of rotten oranges and perform BFS to rot adjacent fresh oranges.
Track the time taken to rot all fresh oranges and return -1 if not all fresh oranges can be rotten.
Update the grid with the new state of oranges after each second.
Handle edge cases such as empty grid or no fresh oranges present.
Example: For the given grid, the minimum time required is 4 secon...read more
Q72. Structurally Unique Binary Trees of Dragon Balls
Goku has ‘N’ Dragon Balls, where each Dragon Ball is unique. The ith Dragon Ball has ‘i’ stars on it, meaning the first Dragon Ball has 1 star, the second has 2 ...read more
Count the number of structurally unique binary trees that can be constructed with given Dragon Balls.
Use dynamic programming to solve this problem efficiently.
The number of structurally unique binary trees can be calculated using Catalan numbers.
For each test case, calculate the number of structurally unique binary trees modulo 10^9 + 7.
Return the count of unique binary trees for each test case.
Q73. Chocolate Pickup Problem
Ninja has a 'GRID' of size 'R' x 'C'. Each cell of the grid contains some chocolates. Ninja has two friends, Alice and Bob, and he wants to collect as many chocolates as possible with t...read more
Find the maximum number of chocolates that can be collected by two friends moving in a grid.
Start from the top-left and top-right corners, move diagonally down to collect chocolates
Calculate the total chocolates collected by each friend and sum them up for the final result
Consider all possible paths for both friends to maximize the total chocolates collected
Q74. Fibonacci Membership Check
Given an integer N
, determine if it is a member of the Fibonacci series. Return true
if the number is a member of the Fibonacci series, otherwise return false
.
Fibonacci Series Defini...read more
Check if a given integer is a member of the Fibonacci series.
Implement a function to check if the given number is a perfect square.
Check if 5*N^2 + 4 or 5*N^2 - 4 is a perfect square to determine Fibonacci membership.
Return true if the number is a perfect square of 5*N^2 + 4 or 5*N^2 - 4, otherwise false.
Q75. Make Array Elements Equal Problem Statement
Given an integer array, your objective is to change all elements to the same value, minimizing the cost. The cost of changing an element from x
to y
is defined as |x ...read more
Find the minimum cost to make all elements of an array equal by changing them to a common value.
Calculate the median of the array and find the sum of absolute differences between each element and the median.
Sort the array and find the median element, then calculate the sum of absolute differences between each element and the median.
If the array has an even number of elements, consider the average of the two middle elements as the median.
Q76. Minimum Time in Wormhole Network
Determine the minimum time required to travel from a starting point to a destination point in a two-dimensional coordinate system, considering both direct movement and the use o...read more
Find the minimum time to travel from a starting point to a destination point using direct movement and wormholes.
Calculate the time taken for direct movement from source to destination.
Consider using each wormhole to see if it reduces the total travel time.
Choose the path with the minimum total time to reach the destination.
Q77. Minimum Moves to Collect All Keys
Given an 'N' x 'M' grid, find the minimum number of moves required to collect all keys when starting at a specified point. Each move allows you to travel to an adjacent cell (u...read more
Find the minimum number of moves required to collect all keys in a grid starting from a specified point.
Use breadth-first search (BFS) to explore all possible paths from the starting point to collect keys.
Keep track of keys collected, locks encountered, and the number of moves taken in each path.
Avoid revisiting cells, and consider the movement rules while traversing the grid.
Return the minimum number of moves to collect all keys, or -1 if it is impossible.
Q78. Shopping Options Problem Statement
Given arrays representing the costs of pants, shirts, shoes, and skirts, and a budget amount 'X', determine the total number of valid combinations that can be purchased such t...read more
Determine total number of valid shopping combinations within budget
Iterate through all possible combinations of items from each array
Check if the total cost of the combination is within the budget
Return the count of valid combinations
Q79. Unlock the Briefcase Problem Statement
You have a briefcase secured by a lock with 4 circular wheels. The password is a sequence of 4 digits. Each wheel has 10 slots labeled ‘0’ through ‘9’. The wheels can rota...read more
Find the minimum number of rotations required to unlock a briefcase with a given target code, considering dead-end codes.
Iterate through all possible combinations of rotations to find the shortest path to the target code.
Use a queue to efficiently explore all possible combinations.
If the target code is a dead-end code, return -1 as it is not feasible to unlock the briefcase.
Q80. 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
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.
Terminate recursion when the number of open and close parentheses used equals the given number of pairs.
Q81. Intersection of Two Arrays Problem Statement
Given two arrays A
and B
with sizes N
and M
respectively, both sorted in non-decreasing order, determine their intersection.
The intersection of two arrays includes ...read more
The problem is to find the intersection of two sorted arrays.
Use two pointers to iterate through the arrays.
Compare the elements at the current pointers and move the pointers accordingly.
If the elements are equal, add it to the intersection array and move both pointers.
If the element in the first array is smaller, move the first pointer.
If the element in the second array is smaller, move the second pointer.
Repeat until one of the pointers reaches the end of its array.
Return t...read more
Q82. Longest Common Prefix After Rotation
You are given two strings 'A' and 'B'. While string 'A' is constant, you may apply any number of left shift operations to string 'B'.
Explanation:
Your task is to calculate ...read more
Calculate the minimum number of left shift operations needed to achieve the longest common prefix between two strings.
Apply left shift operations to string B to find the longest common prefix with string A
Count the number of left shifts needed to achieve the longest common prefix
Return the minimum number of left shift operations for each test case
Q83. Maximum Meetings Problem Statement
Given the schedule of N meetings with their start time Start[i]
and end time End[i]
, you need to determine which meetings can be organized in a single meeting room such that t...read more
Given N meetings with start and end times, find the maximum number of meetings that can be organized in a single room without overlap.
Sort the meetings based on their end times.
Iterate through the sorted meetings and select the next meeting that does not overlap with the current meeting.
Keep track of the selected meetings and return their indices in the order they are organized.
Q84. Minimum Operations Problem Statement
You are given an array 'ARR'
of size 'N'
consisting of positive integers. Your task is to determine the minimum number of operations required to make all elements in the arr...read more
The minimum number of operations needed to make all elements of the array equal by performing addition, multiplication, subtraction, or division on any element.
Iterate through the array and find the maximum and minimum values
Calculate the difference between the maximum and minimum values
Check if the difference is divisible by the length of the array
If divisible, return the difference divided by the length
If not divisible, return the difference divided by the length plus one
Q85. 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
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
Q86. Pair Sum Problem Statement
You are provided with an array ARR
consisting of N
distinct integers in ascending order and an integer TARGET
. Your objective is to count all the distinct pairs in ARR
whose sum equal...read more
Count distinct pairs in an array whose sum equals a given target.
Use two pointers approach to iterate through the array and find pairs with sum equal to target.
Keep track of visited pairs to avoid counting duplicates.
Return -1 if no such pair exists with the given target.
Q87. Path Queries Problem Statement
Consider a weighted, undirected graph with 'V' vertices numbered from 1 to 'V' and 'E' bidirectional edges. You are tasked with handling 'Q' queries. For each query, you are given...read more
Implement a function to find the shortest distance between two vertices in a weighted, undirected graph.
Use Dijkstra's algorithm to find the shortest path between the given vertices.
Create a graph data structure to represent the weighted, undirected graph.
Handle cases where no path exists between the given vertices by returning -1.
Optimize the algorithm to handle multiple queries efficiently.
Consider edge cases such as when the same vertex is given for both 'u' and 'v'.
Q88. Smallest Window Problem Statement
Given two strings S
and X
containing random characters, the task is to find the smallest substring in S
which contains all the characters present in X
.
Input:
The first line co...read more
Find the smallest substring in S containing all characters in X.
Use a sliding window approach to find the smallest window in S containing all characters in X.
Keep track of the characters in X using a hashmap.
Slide the window to the right until all characters in X are found, then shrink the window from the left to find the smallest window.
Q89. Binary Tree Construction from Preorder and Inorder Traversal
The goal is to construct a binary tree from given preorder and inorder traversal lists of the tree nodes.
Example:
Input:
preorder = [1, 2, 4, 7, 3]
i...read more
The task is to construct a binary tree using the given inorder and preorder traversals.
Use the preorder traversal to determine the root of the binary tree
Use the inorder traversal to determine the left and right subtrees of the root
Recursively construct the left and right subtrees
Return the root node of the constructed binary tree
Q90. Contains Duplicate Problem Statement
Given an array of integers ARR
and an integer K
, determine if there exist two distinct indices i
and j
such that ARR[i] == ARR[j]
and | i - j | <= K
.
Input:
The first line c...read more
Given an array of integers and an integer K, determine if there exist two distinct indices i and j such that ARR[i] == ARR[j] and | i - j | <= K.
Iterate through the array and keep track of the indices of each element using a hashmap.
Check if the current element already exists in the hashmap within a distance of K.
Return 'Yes' if a pair of such indices exists, otherwise return 'No'.
Q91. Delete the Middle Node from a Singly Linked List
Given a singly linked list of integers, the task is to remove the middle node from this list.
Input:
The first line of input includes an integer 'T' which denote...read more
The task is to delete the middle node of a singly linked list of integers.
If the linked list is empty or has only one node, there is no middle node to delete.
To delete the middle node, we need to find the middle node and update the pointers of the previous and next nodes.
To find the middle node in one traversal, we can use two pointers - a slow pointer and a fast pointer.
The slow pointer moves one node at a time, while the fast pointer moves two nodes at a time.
When the fast ...read more
Q92. Duplicate Integer in Array
Given an array ARR
of size N
, containing each number between 1 and N-1
at least once, identify the single integer that appears twice.
Input:
The first line contains an integer, 'T', r...read more
Identify the duplicate integer in an array containing numbers between 1 and N-1.
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 integer.
Time complexity can be optimized to O(N) using Floyd's Tortoise and Hare algorithm.
Example: For input [1, 2, 3, 4, 4], the output should be 4.
Q93. Find a Node in Linked List
Given a singly linked list of integers, your task is to implement a function that returns the index/position of an integer value 'N' if it exists in the linked list. Return -1 if the ...read more
Implement a function to find the index of a given integer in a singly linked list.
Traverse the linked list while keeping track of the index of each element.
Compare each element with the target integer 'N'.
Return the index if 'N' is found, otherwise return -1.
Handle cases where the list is empty or 'N' is not found.
Consider the constraints on the number of test cases and the length of the linked list.
Q94. Maximum Path Sum Between Two Leaves
Given a non-empty binary tree where each node has a non-negative integer value, determine the maximum possible sum of the path between any two leaves of the given tree.
Expla...read more
Find the maximum path sum between two leaf nodes in a binary tree.
Traverse the tree to find the maximum path sum between two leaf nodes
Consider both cases where the path passes through the root and where it doesn't
Use recursion to calculate the sum of paths from each leaf node to the root
Q95. 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
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
Q96. Minimum Travel Cost Problem
You are given a country called 'Ninjaland' with 'N' states, numbered from 1 to 'N'. These states are connected by 'M' bidirectional roads, each with a specified travel cost. The aim ...read more
Find the minimum cost selection of roads to travel to every state in a country.
Create a graph representation of the states and roads with their costs.
Use a minimum spanning tree algorithm like Kruskal's or Prim's to find the optimal roads.
Select 'N' - 1 roads with the lowest costs to cover all states.
Return the selected roads and their costs as output.
Q97. Morty's Array Challenge
Rick has provided Morty with an array 'Arr' of length 'N' and an integer 'K'. Morty needs to split the array into non-empty sub-arrays to achieve the minimum possible cost, subject to th...read more
The challenge involves splitting an array into sub-arrays to minimize cost based on unique elements and repetitions.
Iterate through the array and keep track of unique elements and repetitions
Calculate cost for each sub-array based on the rules provided
Sum up the costs for all sub-arrays to get the total minimum cost
Q98. Number Pattern Problem Statement
Design a seating arrangement for a high-security meeting. There are 'N' rows of tables set up where the first row contains one table, the second row contains two tables, and so ...read more
Design a seating arrangement for a high-security meeting with specific table assignments for security personnel and guests.
Create a loop to iterate through each row from 1 to N.
Assign tables on either end of each row to security personnel.
For rows with only one table, assign it to security personnel.
Display the seating arrangement with the number of people at each table.
Example: For 4 rows, the output pattern is 1, 11, 121, 1221.
Q99. Rabbit Jumping Problem
Consider 'n' carrots numbered from 1 to 'n' and 'k' rabbits. Each rabbit jumps to carrots only at multiples of its respective jumping factor Aj (i.e., Aj, 2Aj, 3Aj, ...), for all rabbits ...read more
Calculate uneaten carrots by rabbits with specific jumping factors.
Iterate through each carrot and check if any rabbit jumps on it.
Use the jumping factors to determine which carrots will be eaten.
Subtract the eaten carrots from the total to get the uneaten carrots.
Q100. Reverse a Stack Using Recursion
You are given a stack of integers. Your task is to reverse the stack using recursion without using any extra space other than the internal stack space used due to recursion. You ...read more
Reverse a stack using recursion without using any extra space other than the internal stack space.
Use recursion to pop all elements from the original stack and store them in function call stack
Once the stack is empty, push the elements back in reverse order using recursion
Make use of auxiliary functions to handle the recursion process
Interview Questions of Similar Designations
Top Interview Questions for Software 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