Software Engineer

1500+ Software Engineer Interview Questions and Answers for Freshers

Updated 9 Jul 2025
search-icon

Asked in Capgemini

3d ago

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?

Ans.

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

2d ago

Q. How can you cut a rectangular cake in 8 symmetric pieces in three cuts?

Ans.

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

1d ago

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

Ans.

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

1d ago

Q. What is the reason that the Iterative Waterfall model was introduced?

Ans.

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

Are these interview questions helpful?

Asked in Wipro

4d ago

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

Ans.

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

6d ago

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

Ans.

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

Apple India Pvt Ltd logo
Software Engineer 4-9 years
Apple India Pvt Ltd
4.3
Hyderabad / Secunderabad
CATERPILLAR INDIA ENGINEERING SOLUTIONS PRIVATE LIMITED logo
Software Engineer (Front End /UI Developer ) 6-10 years
CATERPILLAR INDIA ENGINEERING SOLUTIONS PRIVATE LIMITED
4.2
Bangalore / Bengaluru
Lowes Services India Private limited logo
Software Engineer 2-7 years
Lowes Services India Private limited
4.1
₹ 6 L/yr - ₹ 29 L/yr
(AmbitionBox estimate)
Bangalore / Bengaluru

Asked in LinkedIn

1d ago

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

Ans.

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

1d ago

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

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 🌟

man-with-laptop

Asked in Capgemini

1d ago

Q. One question of sorting for a list of people belonging to different cities and states.

Ans.

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'}]

1d ago

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 more
Ans.

The 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

1d ago

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

Ans.

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

2d ago

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

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

4d ago

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

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.

4d ago

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

Ans.

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

4d ago

Q. What are the seven layers of networking?

Ans.

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

1d ago

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

Ans.

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

5d ago

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

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

1d ago

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

Ans.

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

5d ago

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

Ans.

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

3d ago

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

Ans.

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.

2d ago

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

Ans.

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

5d ago

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

Ans.

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

1d ago

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

Ans.

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

6d ago

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

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

Ans.

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.

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

Ans.

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.

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

Ans.

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

1d ago

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

Ans.

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.

6d ago

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

Ans.

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

2d ago

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 more
Ans.

Given 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

1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.7
 • 8.7k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
Cognizant Logo
3.7
 • 5.9k Interviews
View all
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Software Engineer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits