Software Engineer

6500+ Software Engineer Interview Questions and Answers

Updated 16 Dec 2024

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 Duplicate

You have been given an integer array/list(ARR) of size N which contains numbers from 0 to (N - 2). Each number is present at least once. That is, if N = 5, the array/list constitutes values rangin...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. Find Factorial of a Number.

You are given an integer ‘N’. You have to print the value of Factorial of ‘N’. The Factorial of a number ‘N’ is defined as the product of all numbers from 1 to ‘N’.

For Example:
Consi...read more
Q8. N-th Fibonacci Number

You are 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 10^9 +7.

Fi...read more

Software Engineer Jobs

Software Engineer 6-12 years
Maersk Global Service Centres India Pvt. Ltd.
4.3
Bangalore / Bengaluru
Software Engineer 1-6 years
IBM India Pvt. Limited
4.1
Hyderabad / Secunderabad
Software Engineer (Dot Net & React) 6-12 years
Maersk Global Service Centres India Pvt. Ltd.
4.3
Pune

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

Chintu has a long binary string ‘str’. A binary string is a string that contains only 0 and 1. He considers a string ‘beautiful’ if and only if the number of 0's and 1's in the string are equ...read more

Q11. Knapsack

There is a potter who makes pottery wares. With his saving, he can purchase some pottery clay, say ‘K’ units to make pottery wares. He can transform this clay into ‘N’ different items. Each item requir...read more

Q12. Reverse String

You are given a string ‘S’. You are also given ‘M’ integers in an array ‘A’. You perform ‘M’ operations on this string. The operations are given in an array ‘A’ of size ‘M’.

You perform the operat...read more

Q13. Maximum Sum Subarray

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

For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would ...read more

Q14. Nth Element Of Modified Fibonacci Series

You have been given two integers ‘X’ and ‘Y’ which are the first two integers of a series and an integer ‘N’. You have to find the Nth number of the series using the Fibo...read more

Q15. Puzzle

A man fell in a 50m deep well. He climbs 4 meters up and slips 3 meters down in one day. How many days would it take for him to come out of the well?

Q16. Second largest element in the array

You have been given an array/list 'ARR' of integers. Your task is to find the second largest element present in the 'ARR'.

Note:
a) Duplicate elements may be present. b) If no...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.

Q17. Reverse Linked List

Given a singly linked list of integers. Your task is to return the head of the reversed linked list.

For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked lis...read more
Frequently asked in, ,

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

Q19. Set Matrix Zeros

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. In particular, your task is to modify it in such a way that if a cell has a va...read more

Q20. Implement indexOf()

You are given two strings A and B. Find the index of the first occurrence of A in B. If A is not present in B, then return -1.

For Example:
A = “bc”, B = “abcddbc”. String “A” is present at ...read more
Q21. Maximum Sum Subarray

You are given an array (ARR) of length N, consisting of integers. You have to find the sum of the subarray (including empty subarray) having maximum sum among all subarrays.

A subarray is a ...read more

Q22. Spiral Matrix

You are given a 2-D array 'MATRIX' of dimensions N x M, of integers. You need to return the spiral path of the matrix.

Example Of Spiral Path:

Spiral path of a matrix

Input Format:
The first line contains an integer 'T' ...read more
Q23. Check If The String Is A Palindrome

You are given a string 'S'. Your task is to check whether the string is palindrome or not. For checking palindrome, consider alphabets and numbers only and ignore the symbols ...read more

Q24. City of Happy People

Ninja is traveling to a Happy city where ‘N’ people reside. In the city, the happiness of each person is represented as a number ‘H’ where ‘H’ ranges from -20,000,000 to 20,000,000 (both inc...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

Q25. Count ways to reach the n’th stair

You have been given a number of stairs. Initially, you are at the 0th stair, and you need to reach the Nth stair. Each time you can either climb one step or two steps. You are ...read more

Q26. Maximum Subarray Sum

You are given an array (ARR) of length N, consisting of integers. You have to find the sum of the subarray (including empty subarray) having maximum sum among all subarrays.

A subarray is a ...read more

Q27. Sum of Two Arrays

You are given two numbers 'A' and 'B' in the form of two arrays (A[] and B[]) of lengths 'N' and 'M' respectively, where each array element represents a digit. You need to find the sum of these...read more

Q28. Best Time to Buy and Sell Stock

You are given an array/list 'prices' where the elements of the array represent the prices of the stock as they were yesterday and indices of the array represent minutes. Your task...read more

Q29. Compress the String

Ninja has been given a program to do basic string compression. For a character that is consecutively repeated more than once, he needs to replace the consecutive duplicate occurrences with th...read more

Q30. Two Sum

You are 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 Target.

Note:

We cannot use the element at a given inde...read more
Frequently asked in,

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

Q32. Reverse a number

Write a program to generate the reverse of a given number N. Print the corresponding reverse number.

Note : If a number has trailing zeros, then its reverse will not include them. For e.g., reve...read more

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

Q34. Common elements between array of strings

Given two 1-dimensional arrays containing strings of lowercase alphabets, print the elements that are common in both the arrays i.e. the strings that are present in both ...read more

Q35. Count Consonants In a String

Given a string ‘STR’ which consists of uppercase and lowercase characters and spaces. Count the number of consonants in the string.

A consonant is an English alphabet character that ...read more

Q36. Split the String

You are given a string ‘str’ of ‘N’ lowercase alphabets. Your task is to check whether it is possible to split the given string into three non-empty substrings such that one of them is a substri...read more

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

Q38. A matrix on n*n size is given with 0s and 1s as values. Wherever a 1 is present make the complete row and column of that element equal to 1. At the end tell how many 1s are present till the complete operation i...read more
Q39. Find prime numbers

You are given a positive integer ‘N’. Your task is to print all prime numbers less than or equal to N.

Note: A prime number is a natural number that is divisible only by 1 and itself. Example ...read more

Frequently asked in,
Q40. K-Palindrome

You are given a string ‘str’. You need to find out whether the string is a K-Palindrome or not.

A string is called a K-Palindrome if, after removing at most ‘k’ characters from the string, it can be...read more

Q41. Remove K Corner Elements

Given an array ‘arr’ consisting of ‘N’ integer elements. You have to remove ‘K’ elements from the beginning or end of the array. Return the maximum possible sum of the remaining array el...read more

Q42. Reverse a string

You are given a string 'STR'. The string contains [a-z] [A-Z] [0-9] [special characters]. You have to find the reverse of the string.

For example:

 If the given string is: STR = "abcde". You hav...read more
Q43. Sum of Two Elements Equals the Third.

You are given an array Arr consisting of n integers, you need to find a valid triplet as explained below.

An array is said to have a valid triplet {arr[i], arr[j], arr[k]} ...read more

Q44. Detect cycle in undirected graph

You have been given an undirected graph with 'N' vertices and 'M' edges. The vertices are labelled from 1 to 'N'.

Your task is to find if the graph contains a cycle or not.

A pat...read more

Q45. Loot Houses

A thief wants to loot houses. He knows the amount of money in each house. He cannot loot two consecutive houses. Find the maximum amount of money he can loot.

Input Format :
The first line of input c...read more
Q46. Merge overlapping intervals

Given 'N' number of intervals, where each interval contains two integers denoting the boundaries of the interval. The task is to merge all the overlapping intervals and return the lis...read more

Q47. Merge Two Sorted Linked Lists

Given a singly linked list of integers. Your task is to return the head of the reversed linked list.

For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse...read more
Q48. Binary strings with no consecutive 1s.

You have been given an integer K.

Your task is to generate all binary strings of length K such that there are no consecutive 1s in the string. This means that the binary st...read more

Q49. Covid Vaccination

We are suffering from the Second wave of Covid-19. The Government is trying to increase its vaccination drives. Ninja wants to help the Government to plan an effective method to help increase v...read more

Q50. Generate all parenthesis

You are given an integer ‘N’, your task is to generate all combinations of well-formed parenthesis having ‘N’ pairs. You are task is to generate all possible valid sets of parenthesis th...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
 • 10k Interviews
3.9
 • 7.8k Interviews
3.7
 • 7.3k Interviews
3.8
 • 5.4k Interviews
3.7
 • 5.2k Interviews
3.8
 • 4.6k Interviews
3.6
 • 3.7k Interviews
3.6
 • 3.6k Interviews
3.6
 • 2.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

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
Get AmbitionBox app

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