Software Engineer

filter-iconFilter interviews by

7000+ Software Engineer Interview Questions and Answers

Updated 21 Feb 2025

Popular Companies

search-icon

Q1. Bridge and torch problem : Four people come to a river in the night. There is a narrow bridge, but it can only hold two people at a time. They have one torch and, because it's night, the torch has to be used wh...

read more
Ans.

Four people with different crossing times need to cross a bridge with a torch. Only two can cross at a time. What is the least time taken?

  • Person A and B cross first, taking 2 minutes

  • A goes back with the torch, taking 1 minute

  • C and D cross together, taking 10 minutes

  • B goes back with the torch, taking 2 minutes

  • A and B cross together, taking 2 minutes

  • Total time taken is 17 minutes

Q2. In a dark room,there is a box of 18 white and 5 black gloves. You are allowed to pick one and then you are allowed to keep it and check it outside. How many turns do you need to take in order for you to find a...

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

Software Engineer Interview Questions and Answers for Freshers

illustration image

Q3. Find the Duplicate Number Problem Statement

Given an integer array 'ARR' of size 'N' containing numbers from 0 to (N - 2). Each number appears at least once, and there is one number that appears twice. Your tas...read more

Ans.

Given an array of size N containing numbers from 0 to (N-2), find and return the duplicate number.

  • Iterate through the array and keep track of the frequency of each number using a hashmap.

  • Return the number with a frequency of 2.

Q4. Tell me something about yourself. Define encapsulation. What is inheritance. What is constructor. What is method overloading. Can we overload a constructor. What is overriding. Difference between overloading an...

read more
Ans.

The interview questions cover topics like encapsulation, inheritance, constructors, method overloading, overriding, exception handling, and hobbies.

  • Encapsulation is the process of hiding the internal details of an object and providing access through methods.

  • Inheritance is a mechanism in which one class inherits the properties and behaviors of another class.

  • A constructor is a special method used to initialize objects.

  • Method overloading is the ability to define multiple methods...read more

Are these interview questions helpful?

Q5. Puzzle : 100 people are standing in a circle .each one is allowed to shoot a person infront of him and he hands the gun to the next to next person for e.g 1st person kills 2nd and hands gun to 3rd .This continu...

read more
Ans.

A puzzle where 100 people shoot the person in front of them until only one person remains.

  • Each person shoots the person in front of them and hands the gun to the next to next person.

  • This continues until only one person remains.

  • The last person standing is the one who was not shot by anyone.

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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. Factorial Calculation Problem

Given an integer N, calculate and print the factorial of N. The factorial of a number N is defined as the product of all positive integers up to N.

Example:

Input:
N = 4
Output:
24...read more

Q8. N-th Fibonacci Number Problem Statement

Given an integer ‘N’, your task is to find and return the N’th Fibonacci number using matrix exponentiation.

Since the answer can be very large, return the answer modulo ...read more

Software Engineer Jobs

Software Engineer 2-5 years
Red Hat India Pvt Ltd
4.3
Bangalore / Bengaluru
Software Engineer 3-5 years
Red Hat India Pvt Ltd
4.3
Pune
Software Engineer-3 2-8 years
Caterpillar Brazil
4.3
Chennai

Q9. What is the difference between a stack and a queue? Give an example where you would use each.

Ans.

A stack is a LIFO data structure while a queue is a FIFO data structure.

  • Stack: Last In First Out (LIFO), used in undo/redo functionality, backtracking, and recursion.

  • Queue: First In First Out (FIFO), used in job scheduling, breadth-first search, and printing.

  • Stack uses push() and pop() operations while queue uses enqueue() and dequeue() operations.

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

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

Q12. Reverse String Operations Problem Statement

You are provided with a string S and an array of integers A of size M. Your task is to perform M operations on the string as specified by the indices in array A.

The ...read more

Q13. Maximum Sum Subarray Problem Statement

Given an array of integers, find the maximum sum of any contiguous subarray within the array.

Example:

Input:
array = [34, -50, 42, 14, -5, 86]
Output:
137
Explanation:

Th...read more

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

Q15. Find the Second Largest Element

Given an array or list of integers 'ARR', identify the second largest element in 'ARR'.

If a second largest element does not exist, return -1.

Example:

Input:
ARR = [2, 4, 5, 6, ...read more
Ans.

The task is to find the second largest element in an array of integers.

  • Iterate through the array and keep track of the largest and second largest elements.

  • Initialize the largest and second largest variables with the first two elements of the array.

  • Compare each element with the largest and second largest variables and update them accordingly.

  • Return the second largest element at the end.

  • Handle the case where no second largest element exists.

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

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

Q18. Set Matrix Zeros Problem Statement

Given an N x M integer matrix, if an element is 0, set its entire row and column to 0's, and return the matrix. Specifically, if a cell has a value 0 (i.e., matrix[i][j] == 0)...read more

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

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

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

Q22. ...read more

Count Ways to Reach the Nth Stair

Given a number of stairs, starting from the 0th stair, calculate the number of distinct ways you can reach the Nth stair. You can climb either one step or two steps at a time.

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

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

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

Q26. Best Time to Buy and Sell Stock Problem Statement

Given an array prices representing the prices of a stock where each element indicates the price at a given minute, determine the maximum profit you can achieve ...read more

Q27. 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
Frequently asked in,

Q28. String Compression Problem Statement

Ninja needs to perform basic string compression. For any character that repeats consecutively more than once, replace the repeated sequence with the character followed by th...read more

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

Q30. Reverse a Number Problem Statement

Create a program to reverse a given integer N. The output should be the reversed integer.

Note:

If a number has trailing zeros, their reversed version should not include them....read more

Q31. Can you describe a challenging technical problem you faced and how you solve it ?

Ans.

Developing a real-time chat application with high scalability and low latency.

  • Designing a distributed architecture to handle a large number of concurrent users.

  • Implementing efficient data synchronization between multiple servers.

  • Optimizing network communication to minimize latency.

  • Ensuring data consistency and reliability in a distributed environment.

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

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

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

Q35. 2 queues q1 and q2 are given.A background process copies elements from q1 to q2.In case an error occurs elements from q2 need to be copied back again to q1.Write this error handling function using foll function...

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

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

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

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

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

Frequently asked in,

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

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

Q42. Detect Cycle in Undirected Graph Problem Statement

You are provided with an undirected graph composed of 'N' vertices and 'M' edges, where vertices are labeled from 1 to 'N'.

Your task is to determine if there ...read more

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

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

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

Q46. Covid Vaccination Distribution Problem

As the Government ramps up vaccination drives to combat the second wave of Covid-19, you are tasked with helping plan an effective vaccination schedule. Your goal is to ma...read more

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

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

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

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

1
2
3
4
5
6
7
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.5k Interviews
3.8
 • 8.2k Interviews
3.6
 • 7.6k Interviews
3.7
 • 5.7k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.8k Interviews
3.5
 • 3.9k Interviews
3.5
 • 3.8k Interviews
3.8
 • 3k Interviews
View all

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

Recently Viewed
COMPARE COMPANIES
Compare & find best workplace
Find best workplace
HOME
Homepage
Empowering your career
DESIGNATION
Team Lead
2.6L salaries
DESIGNATION
Accountant
2.2L salaries
HOME
Homepage
Empowering your career
SALARIES
Cognizant
SALARIES
Accenture
DESIGNATION
DESIGNATION
DESIGNATION
Software Engineer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter