Software Developer
1000+ Software Developer Interview Questions and Answers for Freshers
Popular Companies
Q1. Maximum Subarray Sum Problem Statement
Given an array of integers, determine the maximum possible sum of any contiguous subarray within the array.
Example:
Input:
array = [34, -50, 42, 14, -5, 86]
Output:
137
E...read more
Find the maximum sum of any contiguous subarray within an array of integers.
Iterate through the array and keep track of the maximum sum of subarrays encountered so far.
At each index, decide whether to include the current element in the subarray or start a new subarray.
Use Kadane's algorithm to efficiently find the maximum subarray sum in O(N) time complexity.
Q2. 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
The task is to find the duplicate element in an array of integers.
Iterate through the array and keep track of the frequency of each element using a hash map.
Return the element with a frequency greater than 1.
Alternatively, sort the array and check for adjacent elements with the same value.
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
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
Q4. Crazy Numbers Pattern Challenge
Ninja enjoys arranging numbers in a sequence. He plans to arrange them in 'N' rows such that:
- The first row contains 1 number.
- The second row contains 2 numbers.
- The third row c...read more
Arrange numbers in a sequence in 'N' rows with increasing order and repeating after 9.
Iterate through each test case and for each row, print numbers in increasing order with a loop.
Keep track of the current number to print and reset to 1 after reaching 9.
Handle formatting to align numbers correctly in each row.
Ensure to print the correct number of rows based on the input 'N'.
Q5. Connect Ropes Problem Statement
Given a number of ropes denoted as 'N' and an array containing the lengths of these ropes, your task is to connect the ropes into one single rope. The cost to connect two ropes i...read more
The task is to find the minimum cost required to connect all the ropes by summing their lengths.
Iterate through the ropes and connect the two shortest ropes at each step to minimize cost
Use a priority queue to efficiently find the shortest ropes
Keep track of the total cost as you connect the ropes
Example: For input [4, 3, 2, 6], connect 2 and 3 (cost 5), then connect 4 and 5 (cost 9), then connect 9 and 6 (cost 15) for a total cost of 29
Q6. Minimum Operations to Make Strings Equal
Given two strings, A
and B
, consisting of lowercase English letters, determine the minimum number of pre-processing moves required to make string A
equal to string B
usi...read more
Determine the minimum number of pre-processing moves required to make two strings equal by swapping characters and replacing characters in one string.
Iterate through both strings simultaneously and count the number of characters that need to be swapped.
Consider all possible swaps and replacements to find the minimum number of pre-processing moves.
If the lengths of the strings are different, it's impossible to make them equal.
Handle edge cases like empty strings or strings wit...read more
Share interview questions and help millions of jobseekers 🌟
Q7. Palindromic Numbers Finder
Given an integer 'N', your task is to identify all palindromic numbers from 1 to 'N'. These are numbers that read the same way forwards and backwards.
Input:
The first line provides a...read more
Implement a function to find all palindromic numbers from 1 to N.
Iterate from 1 to N and check if each number is a palindrome
Use string manipulation to check for palindromes
Consider edge cases like single-digit numbers and 11
Q8. Ninja and the New Year Guests Problem
Ninja has organized a new year party and wants to verify if the guests are programmers by challenging them with a coding task. As an invited programmer, you're tasked to so...read more
Compute the number of valid permutations of integers from 0 to N-1 such that at least K positions satisfy ARR[I] = I.
Use dynamic programming to solve the problem efficiently.
Consider the cases where K is equal to N or N-1 separately.
Modulo the result by 10^9 + 7 to avoid overflow issues.
Software Developer Jobs
Q9. Trapping Rain Water Problem Statement
You are given a long type array/list ARR
of size N
, representing an elevation map. The value ARR[i]
denotes the elevation of the ith
bar. Your task is to determine the tota...read more
The question asks to find the total amount of rainwater that can be trapped in the given elevation map.
Iterate through the array and find the maximum height on the left and right side of each bar.
Calculate the amount of water that can be trapped on each bar by subtracting its height from the minimum of the maximum heights on both sides.
Sum up the amount of water trapped on each bar to get the total amount of rainwater trapped.
Q10. Flip Bits Problem Explanation
Given an array of integers ARR
of size N, consisting of 0s and 1s, you need to select a sub-array and flip its bits. Your task is to return the maximum count of 1s that can be obta...read more
Q11. 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
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
Q12. Greatest Common Divisor Problem Statement
You are tasked with finding the greatest common divisor (GCD) of two given numbers 'X' and 'Y'. The GCD is defined as the largest integer that divides both of the given...read more
Find the greatest common divisor (GCD) of two given numbers 'X' and 'Y'.
Iterate from 1 to the minimum of X and Y, check if both X and Y are divisible by the current number, update GCD if true
Use Euclidean algorithm to find GCD: GCD(X, Y) = GCD(Y, X % Y)
If one of the numbers is 0, the other number is the GCD
Handle edge cases like when one of the numbers is 0 or negative
Q13. Order of People Heights Problem Statement
Consider 'N' individuals numbered from 0 to N-1 standing in a queue. You are provided with two arrays: Height
and Infront
, each consisting of 'N' non-negative integers....read more
The task is to find the actual order of people in a queue based on their heights and the number of taller people in front of them.
Iterate through the given arrays and create a list of tuples containing the height and number of taller people for each person.
Sort the list of tuples in descending order of height and ascending order of the number of taller people.
Create an empty result list and insert each tuple into the result list at the index specified by the number of taller ...read more
Q14. Sort 0s, 1s, and 2s Problem Statement
You are provided with an integer array/list ARR
of size 'N' which consists solely of 0s, 1s, and 2s. Your task is to write a solution to sort this array/list.
Input:
The fi...read more
Sort an array of 0s, 1s, and 2s in linear time with a single scan approach.
Use three pointers to keep track of the positions of 0s, 1s, and 2s in the array.
Iterate through the array once and swap elements based on their values and the pointers.
After the single scan, the array will be sorted in place with 0s, 1s, and 2s in order.
Q15. Find K'th Character of Decrypted String
You are given an encrypted string where repeated substrings are represented by the substring followed by its count. Your task is to find the K'th character of the decrypt...read more
Given an encrypted string with repeated substrings represented by counts, find the K'th character of the decrypted string.
Parse the encrypted string to extract substrings and their counts
Iterate through the substrings and counts to build the decrypted string
Track the position in the decrypted string to find the K'th character
Q16. Maximum Subarray Problem Statement
Ninja has been given an array, and he wants to find a subarray such that the sum of all elements in the subarray is maximum.
A subarray 'A' is considered greater than a subarr...read more
The task is to find the subarray with the maximum sum in a given array.
Iterate through the array and keep track of the current sum and maximum sum seen so far.
If the current sum becomes negative, reset it to 0 as it won't contribute to the maximum sum.
Compare the maximum sum with the sum of the current subarray to update the result.
Handle cases where all elements are negative by returning the maximum element in the array.
Consider edge cases like empty array or array with only...read more
Q17. Balanced Sequence After Replacement
Given a string of length 'N' containing only the characters: '[', '{', '(', ')', '}', ']'. At certain places, the character 'X' appears in place of any bracket. Your goal is ...read more
Determine if a valid balanced sequence can be achieved by replacing 'X's with suitable brackets.
Iterate through the string and keep track of the count of opening and closing brackets.
If at any point the count of closing brackets exceeds the count of opening brackets, return False.
If all 'X's can be replaced to form a valid balanced sequence, return True.
Q18. Beautiful String Problem Statement
Given a binary string STR
containing either '0' or '1', determine the minimum number of operations needed to make it beautiful. A binary string is called beautiful if it conta...read more
The problem involves determining the minimum number of operations needed to make a binary string beautiful by ensuring it contains alternating 0s and 1s.
Iterate through the binary string and count the number of operations needed to make it beautiful by flipping the bits as required.
Keep track of the current bit and compare it with the next bit to determine if a flip operation is needed.
Return the total number of operations needed for each test case.
Q19. 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
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
Q20. Alien Dictionary Problem Statement
You are provided with a sorted dictionary (by lexical order) in an alien language. Your task is to determine the character order of the alien language from this dictionary. Th...read more
Q21. Buses Origin Problem Statement
You have been provided with an array where each element specifies the number of buses that can be boarded at each respective bus stop. Buses will only stop at locations that are m...read more
Given an array representing number of buses at each bus stop, determine how many buses originate from each stop.
Iterate through the array and for each element, increment the count of buses originating from the corresponding bus stop.
Use an array to store the count of buses originating from each stop.
Remember to consider the constraint of 1-based indexing for bus stops.
Q22. Largest Cycle in Maze Problem Statement
Given a maze represented by 'N' cells numbered from 0 to N-1, and an array arr
of 'N' integers where arr[i]
denotes the cell number that can be reached from the 'i'-th ce...read more
Identify the length of the largest cycle in a maze represented by cells and an array of integers.
Iterate through each cell and find the cycle length using DFS or Floyd's Tortoise and Hare algorithm.
Handle self-cycles and cells with no exit by checking arr[i] = i and arr[i] = -1 respectively.
Output the length of the largest cycle found or -1 if no cycles exist.
Q23. Maximum Equal Elements After K Operations
You are provided with an array/list of integers named 'ARR' of size 'N' and an integer 'K'. Your task is to determine the maximum number of elements that can be made eq...read more
Determine the maximum number of elements that can be made equal by performing at most K operations on an array of integers.
Sort the array in non-decreasing order to easily identify the elements that need to be increased
Calculate the difference between adjacent elements to determine the number of operations needed to make them equal
Keep track of the total number of operations used and the maximum number of elements that can be made equal
Q24. Permutation in String Problem Statement
Determine if the string str2
contains a permutation of the string str1
as one of its substrings.
Input:
The first line contains an integer 'T', representing the number of...read more
Check if a permutation of one string is a substring of another string.
Create a frequency map of characters in str1.
Iterate through str2 with a window of size N and check if the frequency map matches.
Return 'Yes' if a permutation is found, 'No' otherwise.
Q25. 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.
Q26. 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.
Q27. 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.
Q28. 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.
Q29. 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}
Q30. 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.
Q31. 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.
Q32. 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
Q33. 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.
Q34. 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.
Q35. 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.
Q36. Aggressive Cows Problem Statement
Given an array representing positions of stalls and an integer ‘K’ representing the number of aggressive cows, determine the largest minimum distance between any two cows when ...read more
The problem requires assigning aggressive cows to stalls in a way that maximizes the minimum distance between any two cows.
Sort the array of stall positions in ascending order.
Use binary search to find the largest minimum distance between cows.
Check if it is possible to assign cows with this minimum distance by iterating through the sorted array.
If it is possible, update the maximum distance and continue binary search for a larger minimum distance.
Return the maximum distance ...read more
Q37. 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.
Q38. 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
Q39. 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.
Q40. 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
Q41. 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
Q42. 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.
Q43. 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 backtracking to generate all possible combinations of balanced parentheses.
Keep track of the number of open and close parentheses used in each combination.
Recursively generate combinations by adding open parentheses if there are remaining, and close parentheses if the number of open parentheses is greater than the number of close parentheses.
Q44. 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.
Q45. 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.
Q46. 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
Q47. 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
Q48. 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.
Q49. 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.
Q50. Reverse Array Elements
Given an array containing 'N' elements, the task is to reverse the order of all array elements and display the reversed array.
Explanation:
The elements of the given array need to be rear...read more
Reverse the order of elements in an array and display the reversed array.
Iterate through the array from both ends and swap the elements until the middle is reached.
Use a temporary variable to store the element being swapped.
Print the reversed array after all elements have been swapped.
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