Software Engineer
7000+ Software Engineer Interview Questions and Answers
Popular Companies
Q51. 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
Merge K sorted arrays into a single sorted array.
Iterate through all arrays and merge them into a single array.
Use a min heap to efficiently merge the arrays.
Implement a custom comparator function for the min heap.
Time complexity can be optimized to O(N log K) using min heap.
Q52. Index of First Occurrence Problem Statement
Given two strings A
and B
, determine the index of the first occurrence of A
in B
. If A
is not present in B
, return -1.
Example:
Input:
A = "bc", B = "abcddbc"
Output:...read more
Find the index of the first occurrence of string A in string B.
Iterate through string B and check if a substring of length equal to A matches A.
Return the index of the first occurrence of A in B, or -1 if not found.
Q53. Merge Sort Problem Statement
You are given a sequence of numbers, ARR
. Your task is to return a sorted sequence of ARR
in non-descending order using the Merge Sort algorithm.
Explanation:
The Merge Sort algorit...read more
Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.
Use Divide and Conquer approach to recursively divide the input array into two halves.
Merge the sorted halves to produce a completely sorted array.
Ensure the time complexity is O(n log n) for sorting.
Handle edge cases like empty array, single element array, etc.
Q54. Reverse a String Problem Statement
Given a string STR
containing characters from [a-z], [A-Z], [0-9], and special characters, determine the reverse of the string.
Input:
The input starts with a single integer '...read more
Reverse a given string containing characters from [a-z], [A-Z], [0-9], and special characters.
Iterate through the characters of the string from end to start and append them to a new string to get the reversed string.
Use built-in functions like reverse() or StringBuilder in languages like Java for efficient reversal.
Handle special characters and numbers along with alphabets while reversing the string.
Ensure to print each reversed string on a separate line as per the output for...read more
Q55. Prime Numbers within a Range
Given an integer N, determine and print all the prime numbers between 2 and N, inclusive.
Input:
Integer N
Output:
Prime numbers printed on separate lines
Example:
Input:
N = 10
Out...read more
Generate and print all prime numbers between 2 and N, inclusive.
Iterate from 2 to N and check if each number is prime
Use a helper function to determine if a number is prime
Print each prime number on a new line
Q56. An API is running slow. Upon investigation it was found that SPROC running behind it is perfectly optimized. How can you debug this behavior of API? (You can neglect the resolve time & connect time of the API r...
read moreTo debug the slow behavior of the API, analyze network latency, check for database issues, monitor server performance, and review code for potential bottlenecks.
Analyze network latency to identify any issues with data transmission.
Check for database issues such as slow queries or insufficient indexing.
Monitor server performance to ensure it has enough resources and is not overloaded.
Review the code for potential bottlenecks, such as inefficient algorithms or excessive databas...read more
Share interview questions and help millions of jobseekers 🌟
Q57. Check Word Presence in String
Given a string S
and a list wordList
containing N
distinct words, determine if each word in wordList
is present in S
. Return a boolean array where the value at index 'i' indicates ...read more
Given a string and a list of words, determine if each word in the list is present in the string and return a boolean array indicating their presence.
Iterate through each word in the word list and check if it is present in the string.
Use a boolean array to store the presence of each word in the string.
Remember that the presence of a word is case sensitive.
Do not use built-in string-matching methods.
Return the boolean array without printing it.
Q58. Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A sub...read more
Find the sum of the subarray with the maximum sum among all subarrays in an array of integers.
Iterate through the array and keep track of the maximum sum subarray seen so far.
Use Kadane's algorithm to efficiently find the maximum subarray sum.
Consider the case where all elements in the array are negative.
Handle the case where the array contains only one element.
Software Engineer Jobs
Q59. Merge Two Sorted Arrays Problem Statement
Given two sorted integer arrays ARR1
and ARR2
of size M and N, respectively, merge them into ARR1
as one sorted array. Assume that ARR1
has a size of M + N to hold all ...read more
Merge two sorted arrays into one sorted array in place.
Iterate from the end of both arrays and compare elements to merge in place
Use two pointers to keep track of the current position in each array
Handle cases where one array is fully merged before the other
Q60. Reverse Words in a String: Problem Statement
You are given a string of length N
. Your task is to reverse the string word by word. The input may contain multiple spaces between words and may have leading or trai...read more
Reverse words in a string word by word, removing leading/trailing spaces and extra spaces between words.
Split the input string by spaces to get individual words
Reverse the order of the words
Join the reversed words with a single space in between
Q61. Sudoku Solver
Given a 9x9 Sudoku board, your task is to fill the empty slots and return the completed Sudoku solution.
A Sudoku is a grid composed of nine 3x3 smaller grids. The challenge is to fill in the numb...read more
Implement a Sudoku solver to fill empty slots in a 9x9 grid with numbers 1-9 satisfying constraints.
Create a recursive function to solve the Sudoku puzzle by trying out different numbers in empty slots.
Use backtracking to backtrack and try a different number if a conflict is encountered.
Ensure each number appears only once per row, column, and 3x3 grid.
Return the completed Sudoku grid as the output.
Q62. Water Jug Problem Statement
You have two water jugs with capacities X
and Y
liters respectively, both initially empty. You also have an infinite water supply. The goal is to determine if it is possible to measu...read more
The Water Jug Problem involves determining if a specific amount of water can be measured using two jugs of different capacities.
Start by considering the constraints and limitations of the problem.
Think about how the operations allowed can be used to reach the target measurement.
Consider different scenarios and test cases to come up with a solution.
Implement a function that takes the capacities of the jugs and the target measurement as input and returns True or False based on ...read more
Q63. Print All Permutations of a String
Given an input string STR
, generate and print all possible permutations of the string.
Input:
str
Output:
All permutations of the input string, each on a new line.
Example:
In...read more
Generate and print all possible permutations of a given input string.
Use recursion to generate all permutations by swapping characters in the string.
Maintain a visited array to keep track of characters already used in a particular permutation.
Print each permutation as it is generated.
Handle duplicate characters by skipping swapping if the character is already in the current position.
Q64. Generate All Parentheses Combinations
Given an integer N
, your task is to create all possible valid parentheses configurations that are well-formed using N
pairs. A sequence of parentheses is considered well-fo...read more
Generate all possible valid parentheses configurations with N pairs.
Use backtracking to generate all possible combinations of parentheses.
Keep track of the number of open and close parentheses used.
Add '(' if there are remaining open parentheses, and add ')' if there are remaining close parentheses.
Q65. Bubble Sort Problem Statement
Sort the given unsorted array consisting of N non-negative integers in non-decreasing order using the Bubble Sort algorithm.
Input:
The first line contains an integer 'T' represent...read more
Bubble Sort is used to sort an array of non-negative integers in non-decreasing order.
Iterate through the array and compare adjacent elements, swapping them if they are in the wrong order.
Repeat this process until the array is sorted.
Time complexity of Bubble Sort is O(n^2) in worst case.
Space complexity of Bubble Sort is O(1) as it sorts the array in place.
Q66. Maximum Difference Problem Statement
Given an array ARR
of N
elements, your task is to determine the maximum difference between any two elements in ARR
.
If the maximum difference is even, print EVEN
. If the max...read more
Find the maximum difference between any two elements in an array and determine if it is even or odd.
Iterate through the array to find the maximum and minimum elements.
Calculate the difference between the maximum and minimum elements.
Check if the difference is even or odd and return the result.
Q67. Nth Fibonacci Number Problem Statement
Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2)
, with initial conditions F(1) = F(2) = 1
.
Input:
The inp...read more
Calculate the Nth Fibonacci number efficiently using dynamic programming.
Use dynamic programming to store previously calculated Fibonacci numbers to avoid redundant calculations.
Start with base cases F(1) and F(2) as 1, then iterate to calculate subsequent Fibonacci numbers.
Return the Nth Fibonacci number as the final result.
Q68. Prime Numbers Identification
Given a positive integer N
, your task is to identify all prime numbers less than or equal to N
.
Explanation:
A prime number is a natural number greater than 1 that has no positive d...read more
Identify all prime numbers less than or equal to a given positive integer N.
Iterate from 2 to N and check if each number is prime
Use the Sieve of Eratosthenes algorithm for efficient prime number identification
Optimize by only checking up to the square root of N for divisors
Q69. 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
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
Q70. 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 determine 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 value in the table will represent the total number of ways to make change for the target value.
Consider edge cases such as when the target v...read more
Q71. Dance Team Pairing Challenge
Imagine you are helping Ninja, a dance coach, who needs to form dance pairs from the available boys and girls in a studio. Given the number of boys N
, the number of girls M
, and the...read more
The challenge involves forming dance pairs from available boys and girls based on potential pairings to maximize the number of pairs.
Parse the input to get the number of test cases, boys, girls, and potential pairings.
Iterate through the potential pairings and form pairs based on the given indexes.
Output '1' if a set of maximum possible pairs is returned, else output '0'.
There can be multiple valid configurations of pairs.
Example: For input '2 2 2' and pairings '1 1' and '2 2...read more
Q72. Longest Consecutive Sequence Problem Statement
You are provided with an unsorted array/list ARR
of N
integers. Your task is to determine the length of the longest consecutive sequence present in the array.
Expl...read more
The task is to find the length of the longest consecutive sequence in an unsorted array of integers.
Sort the array to bring consecutive numbers together
Iterate through the sorted array and keep track of the current consecutive sequence length
Update the maximum length if a longer sequence is found
Q73. Minimum Number of Platforms Needed Problem Statement
You are given the arrival and departure times of N trains at a railway station for a particular day. Your task is to determine the minimum number of platform...read more
The task is to determine the minimum number of platforms needed at a railway station based on arrival and departure times of trains.
Sort the arrival and departure times in ascending order.
Use two pointers to track overlapping schedules.
Increment platform count when a new train arrives before the previous one departs.
Q74. Palindrome String Validation
Determine if a given string 'S' is a palindrome, considering only alphanumeric characters and ignoring spaces and symbols.
Note:
The string 'S' should be evaluated in a case-insensi...read more
Validate if a given string is a palindrome after removing special characters, spaces, and converting to lowercase.
Remove special characters and spaces from the input string
Convert the string to lowercase
Check if the modified string is equal to its reverse to determine if it's a palindrome
Q75. Reverse Stack with Recursion
Reverse a given stack of integers using recursion. You must accomplish this without utilizing extra space beyond the internal stack space used by recursion. Additionally, you must r...read more
Reverse a given stack of integers using recursion without using extra space or loops.
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
Use the top(), pop(), and push() methods to manipulate the stack
Q76. String Compression Task
Develop an algorithm that compresses a string by replacing consecutive duplicate characters with the character followed by the count of its repetitions, if that count exceeds 1.
Example:...read more
Develop an algorithm to compress a string by replacing consecutive duplicate characters with the character followed by the count of its repetitions.
Iterate through the input string while keeping track of consecutive character counts.
Replace consecutive duplicate characters with the character followed by the count if count exceeds 1.
Ensure the count does not exceed 9 for each character.
Return the compressed string as output.
Q77. Write a program for Fibonacci series for n terms where n is the user input.
Program for Fibonacci series for n terms with user input.
Take user input for n
Initialize variables for first two terms of Fibonacci series
Use a loop to generate the series up to n terms
Print the series
Q78. Total time: 110 mins 1. Find missing and duplicate numbers from given array(algo, code, optimization, dry run, complexity analysis) 2. Flatten Binary tree to Linked List Conversion (algo, code, optimization, dr...
read moreInterview questions for Software Engineer position
Array manipulation and linked list operations
Tree data structure and balancing techniques
Database concepts and differences between SQL and NoSQL
Web development frameworks and protocols
Concepts of Deadlock and Race Condition
Use of pointers in function oriented programming and their absence in Java
Q79. If your Wi-Fi router is not working then what you will do to fix it?
I will troubleshoot the router by checking the power supply, resetting the router, and checking the network settings.
Check if the router is properly plugged in and receiving power
Reset the router by turning it off and on again
Check the network settings and make sure they are correct
Try connecting to the router with a different device
If all else fails, contact the internet service provider for assistance
Q80. Character Frequency in Order of Occurrence
For the given string S
of length N
, determine the frequency of each character from 'a' to 'z' appearing within S
.
Input:
The first input line contains an integer 'T' r...read more
The task is to determine the frequency of each character from 'a' to 'z' in a given string.
Create an array of size 26 to store the frequency of each character from 'a' to 'z'.
Iterate through the input string and increment the corresponding index in the array for each character encountered.
Output the array of frequencies for each test case.
Q81. 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'.
Implement a function to calculate the GCD of two numbers using Euclidean algorithm
Iteratively find the remainder of dividing the larger number by the smaller number until the remainder is 0
The last non-zero remainder is the GCD of the two numbers
Q82. On a dark night, 4 people want to cross a bridge and they have only one torch. At a time at max 2 people can cross the bridge. The time required for each individual to cross the bridge is 1, 2, 5, and 10 minute...
read more4 people with different crossing times need to cross a bridge with one torch. Only 2 can cross at a time. What's the minimum time?
The person with the longest time should always be accompanied by someone else
The two fastest people should cross together to save time
The torch needs to be brought back to the starting side every time two people cross
The total time taken will be the sum of all individual crossing times
Q83. Left View of a Binary Tree Problem Statement
Given a binary tree, your task is to print the left view of the tree.
Example:
Input:
The input will be in level order form, with node values separated by a space. U...read more
Print the left view of a binary tree given in level order form.
Traverse the tree level by level and print the first node of each level (leftmost node).
Use a queue to keep track of nodes at each level.
Time complexity should be O(n) where n is the number of nodes in the tree.
Q84. 2)Given an n x n matrix, where every row and column is sorted in increasing order. Given a number x, how to decide whether this x is in the matrix. The designed algorithm should have linear time complexity. a)...
read moreAlgorithm to find if a number is present in a sorted n x n matrix with linear time complexity.
Start with the top right element
Compare the element with x
If equal, return its position
If e < x, move down (if out of bounds, return false)
If e > x, move left (if out of bounds, return false)
Repeat till element is found or returned false
Q85. Boolean Matrix Transformation Challenge
Given a 2-dimensional boolean matrix mat
of size N x M, your task is to modify the matrix such that if any element is 1, set its entire row and column to 1. Specifically,...read more
Modify a boolean matrix such that if any element is 1, set its entire row and column to 1.
Iterate through the matrix and mark rows and columns to be modified
Use additional arrays to keep track of rows and columns to be modified
Update the matrix in-place based on the marked rows and columns
Q86. K-Palindrome Problem Statement
Determine whether a given string str
can be considered a K-Palindrome.
A string is considered a K-Palindrome if it can be transformed into a palindrome after removing up to ‘k’ ch...read more
The problem is to determine whether a given string can be considered a K-Palindrome by removing up to 'k' characters.
Iterate through the string from both ends and check if characters match, if not increment removal count
If removal count is less than or equal to k, return True, else return False
Use dynamic programming to optimize the solution by storing subproblem results
Q87. Missing Number Problem Statement
You are provided with an array named BINARYNUMS
consisting of N
unique strings. Each string represents an integer in binary, covering every integer from 0 to N except for one. Y...read more
Identify the missing integer in an array of binary strings and return its binary representation without leading zeros.
Iterate through the binary strings to convert them to integers and find the missing number using the formula for sum of integers from 0 to N.
Calculate the sum of all integers from 0 to N using the formula (N*(N+1))/2 and subtract the sum of the integers in the array to find the missing number.
Convert the missing integer to binary representation and return it a...read more
Q88. Remove Character from String Problem Statement
Given a string str
and a character 'X', develop a function to eliminate all instances of 'X' from str
and return the resulting string.
Input:
The first line contai...read more
Develop a function to remove all instances of a given character from a string.
Iterate through the string and build a new string excluding the specified character.
Use a StringBuilder or similar data structure for efficient string manipulation.
Handle edge cases such as empty string or character not found in the input string.
Q89. Duplicate Characters in a String
Given a string 'S' of length 'N', identify and return all the characters in the string that appear more than once along with their frequency.
Example:
Input:
N = 5
S = 'GEEK'
O...read more
Identify and return all characters in a string that appear more than once along with their frequency.
Iterate through the string and count the frequency of each character using a hashmap.
Return characters with frequency greater than 1 in an array of tuples.
Q90. How do you stay up to date with emerging technologies and programming language ?
I stay up to date with emerging technologies and programming languages through various methods.
I regularly read tech blogs and news websites to stay informed about the latest trends and advancements.
I participate in online forums and communities where developers discuss new technologies and share their experiences.
I attend conferences, workshops, and webinars to learn from industry experts and network with other professionals.
I take online courses and tutorials to enhance my ...read more
Q91. 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
Find the node where two linked lists merge, return -1 if no merging occurs.
Traverse both lists to find the lengths and the difference in lengths
Adjust the starting point of the longer list to match the length of the shorter list
Traverse both lists in parallel until the nodes match, return the data of the matching node
Q92. Maximize Expression Value
Given an arithmetic expression EXP
containing integer values separated by any of the operators ‘+’, ‘-’, and ‘*’, your task is to place parentheses such that the value of the expressio...read more
Given an arithmetic expression, place parentheses to maximize the value of the expression.
Identify the operators in the expression ('+', '-', '*').
Consider the precedence of operators to determine where to place parentheses.
Calculate the value of the expression with different placements of parentheses to find the maximum value.
Q93. Pythagorean Triplets Detection
Determine if an array contains a Pythagorean triplet by checking whether there are three integers x, y, and z such that x2 + y2 = z2 within the array.
Input:
The first line contai...read more
Detect if an array contains a Pythagorean triplet by checking if there are three integers x, y, and z such that x^2 + y^2 = z^2.
Iterate through all possible combinations of three integers in the array and check if x^2 + y^2 = z^2.
Use a nested loop to generate all possible combinations efficiently.
Return 'yes' if a Pythagorean triplet is found, otherwise return 'no'.
Q94. Reverse a Singly Linked List
Given a singly linked list of integers, your task is to return the head of the reversed linked list.
Explanation:
Reverse a given singly linked list so that the last element becomes...read more
Reverse a singly linked list of integers.
Iterate through the linked list and reverse the pointers to point to the previous node instead of the next node.
Keep track of the current, previous, and next nodes while traversing the list.
Update the head of the linked list to be the last node encountered during traversal.
Q95. Sum Between Zeroes Problem Statement
Given a singly linked list containing a series of integers separated by the integer '0', modify the list by merging nodes between two '0's into a single node. This merged no...read more
Merge nodes between zeroes in a linked list to store the sum of included nodes.
Traverse the linked list and keep track of sum between zeroes
Merge nodes between zeroes by updating the sum in the merged node
Handle edge cases like empty list or single node between zeroes
Ensure the list starts and ends with a zero
Q96. For Example: N Cards are placed, if you flip a card, the next card will get reversed. If we move left to right, how much time will it take to get all cards reversed- question based on time complexity?
To reverse N cards, time complexity is O(N).
The time complexity to reverse N cards is O(N).
The algorithm needs to flip each card once, so the time complexity is linear.
The time it takes to reverse all cards is directly proportional to the number of cards.
For example, if there are 10 cards, it will take 10 flips to reverse all of them.
Q97. 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.
Create a function that takes an array as input
Use a loop to iterate through the array and swap elements at opposite ends
Return the reversed array
Q98. 4)Given a set of integers, Display the non-empty subsets whose sum is zero. For example, given the set { −7, −3, −2, 5, 8}, the answer is the subset { −3, −2, 5} which sums to zero. This is the special case of...
read moreThe problem is to find non-empty subsets of a given set of integers whose sum is zero.
The problem is a special case of the knapsack problem and is known to be NP-Complete.
A brute-force approach would involve generating all subsets and checking their sums.
The brute-force approach has an exponential time complexity.
There is no known polynomial time solution for this problem.
Q99. Cube of Matrix Problem Statement
Given a 2D array 'MATRIX' of size M x N, find and return the value (i * i + j * j) for those elements where the sum of the cubes of its digits equals the element itself. Here, '...read more
Given a 2D array, find elements where sum of cube of digits equals element itself and return (i * i + j * j) value.
Iterate through the 2D array and check if the sum of cube of digits equals the element itself.
Calculate (i * i + j * j) for such elements and return the values.
If no such element exists, return -1.
Q100. Matrix Multiplication Task
Given two sparse matrices MAT1
and MAT2
of integers with dimensions 'N' x 'M' and 'M' x 'P' respectively, the goal is to determine the resulting matrix produced by their multiplicatio...read more
Implement a function to multiply two sparse matrices and return the resulting matrix.
Create a function that takes two sparse matrices as input and returns the resulting matrix after multiplication.
Iterate through the non-zero elements of the matrices to perform the multiplication efficiently.
Ensure to handle the sparse nature of the matrices to optimize the multiplication process.
Consider the constraints provided to ensure the function works within the specified limits.
Test t...read more
Interview Questions of Similar Designations
Top Interview Questions for Software Engineer 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