Software Engineer
1500+ Software Engineer Interview Questions and Answers for Freshers

Asked in Capgemini

Q. In a dark room, there is a box of 18 white and 5 black gloves. You are allowed to pick one, keep it, and check it outside. How many turns do you need to take to find a perfect pair?
You need to take 36 turns to find a perfect pair.
You need to pick 19 gloves to ensure a perfect pair.
The worst case scenario is picking 18 white gloves and then the 19th glove is black.
In that case, you need to pick 17 more gloves to find a black one and complete the pair.

Asked in Capgemini

Q. How can you cut a rectangular cake in 8 symmetric pieces in three cuts?
Cut the cake in half horizontally, then vertically, and finally cut each half diagonally.
Cut the cake horizontally through the middle.
Cut the cake vertically through the middle.
Cut each half diagonally from corner to corner.
Ensure each cut is made symmetrically to get 8 equal pieces.
Example: https://www.youtube.com/watch?v=ZdGmuCJzQFo

Asked in JPMorgan Chase & Co.

Q. Split Binary String Problem Statement
Chintu has a long binary string str
. A binary string is a string that contains only 0 and 1. He considers a string to be 'beautiful' if and only if the number of 0's and 1'...read more
The task is to split a binary string into beautiful substrings with equal number of 0's and 1's.
Count the number of 0's and 1's in the string.
Iterate through the string and split it into beautiful substrings whenever the count of 0's and 1's becomes equal.
Return the maximum number of beautiful substrings that can be formed.
If it is not possible to split the string into beautiful substrings, return -1.

Asked in TCS

Q. What is the reason that the Iterative Waterfall model was introduced?
Iterative Waterfall model was introduced to address the limitations of the traditional Waterfall model.
Iterative Waterfall model allows for feedback and changes during the development process.
It breaks down the development process into smaller, more manageable stages.
It reduces the risk of project failure by identifying and addressing issues early on.
It allows for better collaboration between developers and stakeholders.
Examples include Rational Unified Process (RUP) and Agil...read more

Asked in Wipro

Q. Knapsack Problem Statement
There is a potter with a limited amount of pottery clay (denoted as 'K' units) who can make 'N' different items. Each item requires a specific amount of clay and yields a certain prof...read more
The Knapsack Problem involves maximizing profit by choosing which items to make with limited resources.
Understand the problem statement and constraints provided.
Implement a dynamic programming solution to solve the Knapsack Problem efficiently.
Iterate through the items and clay units to calculate the maximum profit that can be achieved.
Consider both the clay requirement and profit of each item while making decisions.
Ensure the solution runs within the given time limit of 1 se...read more

Asked in MAQ Software

Q. Nth Element Of Modified Fibonacci Series
Given two integers X
and Y
as the first two numbers of a series, and an integer N
, determine the Nth element of the series following the Fibonacci rule: f(x) = f(x - 1) ...read more
Calculate the Nth element of a modified Fibonacci series given the first two numbers and N, with the result modulo 10^9 + 7.
Implement a function to calculate the Nth element of the series using the Fibonacci rule f(x) = f(x - 1) + f(x - 2)
Return the answer modulo 10^9 + 7 due to the possibility of a very large result
The series starts with the first two numbers X and Y, and the position N in the series
Software Engineer Jobs




Asked in LinkedIn

Q. Split the String Problem Statement
You are given a string str
consisting of N
lowercase alphabets. Your task is to determine if it is possible to divide the string into three non-empty substrings such that one ...read more
Determine if it is possible to divide a string into three non-empty substrings where one is a substring of the other two.
Check if any substring of the string is a substring of the other two substrings.
Iterate through all possible divisions of the string into three non-empty substrings.
Use two pointers to find all possible substrings efficiently.

Asked in Amazon

Q. 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
Find all pairs of elements in an array that add up to a given target.
Iterate through the array and use a hashmap to store the difference between the target and current element.
Check if the current element exists in the hashmap, if so, print the pair.
If no pair is found, print (-1, -1).
Share interview questions and help millions of jobseekers 🌟

Asked in Capgemini

Q. One question of sorting for a list of people belonging to different cities and states.
Sort a list of people by their cities and states.
Use a sorting algorithm like quicksort or mergesort.
Create a custom comparator function that compares the city and state of each person.
If two people belong to the same city and state, sort them by their names.
Example: [{name: 'John', city: 'New York', state: 'NY'}, {name: 'Jane', city: 'Boston', state: 'MA'}]
Example output: [{name: 'Jane', city: 'Boston', state: 'MA'}, {name: 'John', city: 'New York', state: 'NY'}]

Asked in Marvel Realtors

Q. Given two queues, q1 and q2, where a background process copies elements from q1 to q2, write an error handling function to copy elements from q2 back to q1 if an error occurs. Use the following functions: q_len...
read moreThe error handling function copies elements from q2 back to q1 in case of an error.
Use q_len() to get the length of the queues
Use q_insert() and q_remove() to manipulate the queues
Iterate through q2 and use q_insert() to copy elements back to q1

Asked in InterviewBit

Q. Sum of Two Numbers Represented as Arrays
Given two numbers in the form of two arrays where each element of the array represents a digit, calculate the sum of these two numbers and return this sum as an array.
E...read more
Given two numbers represented as arrays, calculate their sum and return the result as an array.
Iterate through the arrays from right to left, adding digits and carrying over if necessary
Handle cases where one array is longer than the other by considering the remaining digits
Ensure the final sum array does not have any leading zeros

Asked in Samsung

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

Asked in Adobe

Q. Spiral Matrix Path Problem
You are provided with a two-dimensional array named MATRIX
of size N x M, consisting of integers. Your task is to return the elements of the matrix following a spiral order.
Input:
Th...read more
Implement a function to return elements of a matrix in spiral order.
Iterate through the matrix in a spiral order by adjusting boundaries as you move along.
Keep track of the direction of movement (right, down, left, up) to traverse the matrix correctly.
Handle edge cases like when the matrix is a single row or column separately.

Asked in Jio Platforms

Q. Maximum Sum After Removing K Corner Elements
Given an array arr
of 'N' integer elements, your goal is to remove 'K' elements from either the beginning or the end of the array. The task is to return the maximum ...read more
Given an array of integers, remove K elements from either end to maximize sum of remaining elements.
Iterate through all possible combinations of removing K elements from start and end
Calculate sum of remaining elements for each combination
Return the maximum sum obtained

Asked in Capgemini

Q. What are the seven layers of networking?
The seven layers of networking refer to the OSI model which defines how data is transmitted over a network.
The seven layers are: Physical, Data Link, Network, Transport, Session, Presentation, and Application.
Each layer has a specific function and communicates with the layers above and below it.
For example, the Physical layer deals with the physical transmission of data, while the Application layer deals with user interfaces and applications.
Understanding the OSI model is imp...read more

Asked in Amazon

Q. Loot Houses Problem Statement
A thief is planning to steal from several houses along a street. Each house has a certain amount of money stashed. However, the thief cannot loot two adjacent houses. Determine the...read more
Determine the maximum amount of money a thief can steal from houses without looting two consecutive houses.
Create an array 'dp' to store the maximum money that can be stolen up to the i-th house.
Iterate through the houses and update 'dp' based on whether the current house is stolen or not.
Return the maximum value in 'dp' as the answer.
Example: For input N=4 and values=[6, 7, 1, 30], the output should be 36.

Asked in Paytm

Q. Generate Binary Strings with No Consecutive 1s
Given an integer K
, your task is to produce all binary strings of length 'K' that do not contain consecutive '1's.
Input:
The input begins with an integer 'T', the...read more
Generate all binary strings of length 'K' with no consecutive '1's in lexicographically increasing order.
Use backtracking to generate all possible binary strings without consecutive '1's.
Start with an empty string and recursively add '0' or '1' based on the condition.
Keep track of the current string and its length to ensure no consecutive '1's are added.
Sort the generated strings in lexicographically increasing order before outputting.

Asked in Amazon

Q. Merge Two Sorted Linked Lists Problem Statement
You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.
Input:...read more
Merge two sorted linked lists into a single sorted linked list with constant space complexity and linear time complexity.
Create a dummy node to start the merged list
Compare the values of the two linked lists and append the smaller value to the merged list
Move the pointer of the merged list and the pointer of the smaller value's linked list
Continue this process until one of the linked lists is fully traversed
Append the remaining elements of the other linked list to the merged ...read more

Asked in Amadeus

Q. Matrix Transformation Problem Statement
Given a 2-dimensional matrix of size NxN containing 0s and 1s, the task is to modify the matrix such that, if an element is 1, set its entire row and column to 1. In the ...read more
Modify a matrix by setting entire row and column to 1 if an element is 1, then count the number of 1s.
Iterate through the matrix to find elements with value 1
Use two arrays to keep track of rows and columns to be modified
Update the matrix by setting entire row and column to 1 if an element is 1
Count the number of 1s in the modified matrix

Asked in Barclays

Q. Sum of Two Elements Equals the Third
Determine if a given array contains a valid triplet of integers where two elements sum up to the third. Specifically, find indices i, j, and k such that i != j
, j != k
, and ...read more
Check if a given array contains a valid triplet where two elements sum up to the third.
Iterate through all possible triplets in the array and check if any of the conditions are satisfied.
Use nested loops to compare each element with every other element in the array.
Handle cases where the elements are not distinct by ensuring i != j, j != k, and i != k.

Asked in NXP Semiconductors

Q. City of Happy People Problem Statement
Imagine a city where the happiness of each resident is described by a numerical value. Ninja, who is visiting this city, is interested in forming groups of people such tha...read more
The problem is to find the number of ways to form a group of people such that the overall happiness of the group falls within a given range.
Iterate through all possible subsets of the given array/list
Calculate the sum of happiness values for each subset
Count the number of subsets whose sum falls within the given range

Asked in Goldman Sachs

Q. Merge Overlapping Intervals Problem Statement
Given a specified number of intervals, where each interval is represented by two integers denoting its boundaries, the task is to merge all overlapping intervals an...read more
Merge overlapping intervals and return sorted list of merged intervals.
Identify overlapping intervals based on start and end times
Merge overlapping intervals to form new intervals
Sort the merged intervals in ascending order of start times

Asked in Bounteous x Accolite

Q. Topological Sort Problem Statement
You are given a directed acyclic graph (DAG). Your task is to perform topological sorting of the graph and return any valid ordering.
Explanation:
A directed acyclic graph is ...read more
Implement a function to perform topological sorting on a directed acyclic graph (DAG) and return any valid ordering.
Create a graph representation using adjacency list or matrix
Perform depth-first search (DFS) to find the topological ordering
Use a stack to keep track of the ordering
Return the ordering as an array of integers

Asked in Meesho

Q. Idempotent Matrix Verification
Determine if a given N * N matrix is an idempotent matrix. A matrix is considered idempotent if it satisfies the following condition:
M * M = M
Input:
The first line contains a si...read more
Check if a given matrix is idempotent by verifying if M * M equals M.
Calculate the product of the matrix with itself and compare it with the original matrix.
If the product equals the original matrix, then it is idempotent.
Iterate through the matrix elements to perform the necessary calculations.


Q. Common Elements Between Array of Strings Problem Statement
Given two 1-dimensional arrays containing strings of lowercase alphabets, determine and return the elements that are common in both arrays, i.e., the s...read more
Given two arrays of strings, find and return the common elements in the order they appear in the second array.
Iterate through the strings in the second array and check if they exist in the first array.
Maintain a set to keep track of common elements to avoid duplicates.
Return the common elements as a single space-separated string in the order they appear in the second array.

Asked in Hewlett Packard Enterprise

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

Asked in Optum Global Solutions

Q. Consonant Counting Problem Statement
Given a string STR
comprising uppercase and lowercase characters and spaces, your task is to count the number of consonants in the string.
A consonant is defined as an Engli...read more
Count the number of consonants in a given string containing uppercase and lowercase characters and spaces.
Iterate through each character in the string and check if it is a consonant (not a vowel).
Keep a count of the consonants encountered while iterating through the string.
Return the total count of consonants at the end.

Asked in Amazon

Q. Longest Common Subsequence Problem Statement
Given two strings, S
and T
with respective lengths M
and N
, your task is to determine the length of their longest common subsequence.
A subsequence is a sequence tha...read more
The task is to find the length of the longest common subsequence between two given strings.
Use dynamic programming to solve this problem efficiently.
Create a 2D array to store the lengths of longest common subsequences of substrings.
Iterate through the strings to fill the array and find the length of the longest common subsequence.
Example: For strings 'abcde' and 'ace', the longest common subsequence is 'ace' with length 3.

Asked in JPMorgan Chase & Co.

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

Asked in TCS

Q. Given a string S consisting of '*' and '#', find the maximum number of '*' or '#' to make it a valid string. The string is considered valid if the number of '*' and '#' are equal. The '*' and '#' can be at any...
read moreGiven a string of '*' and '#', find the maximum number of '*' or '#' to make it a valid string with equal count of both.
Count the number of '*' and '#' in the string
Return the minimum count of '*' and '#' as the maximum valid count
If the count of '*' and '#' is already equal, return that count as the maximum valid count
Interview Questions of Similar Designations
Interview Experiences of Popular Companies





Top Interview Questions for Software Engineer Related Skills



Reviews
Interviews
Salaries
Users

