Software Engineer

1000+ Software Engineer Interview Questions and Answers for Freshers

Updated 16 Dec 2024

Popular Companies

search-icon

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

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

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

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

Are these interview questions helpful?
Q5. 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

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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop
Q7. 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, ,

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

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
JP Morgan Chase - Senior Director - Software Engineering (10-16 yrs) 10-16 years
JP Morgan Chase
4.1
₹ 0 L/yr - ₹ 0 L/yr
Q9. 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
Q10. 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
Q11. 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

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

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

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

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

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

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

Q19. 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
Q20. 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,
Q21. 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

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

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

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

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

Q28. Merge Two Sorted Linked Lists

You are given two sorted linked lists. You have to merge them to produce a combined sorted linked list. You need to return the head of the final linked list.

Note:

The given linked ...read more
Q29. Bubble Sort

Bubble Sort is one of the sorting algorithms that works by repeatedly swapping the adjacent elements of the array if they are not in sorted order.

You are given an unsorted array consisting of N non-...read more

Q30. Longest Common Subsequence

Given two strings, 'S' and 'T' with lengths 'M' and 'N', find the length of the 'Longest Common Subsequence'.

For a string 'str'(per se) of length K, the subsequences are the strings c...read more

Q31. What are 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

Q32. Merge Sort

Given a sequence of numbers ‘ARR’. Your task is to return a sorted sequence of ‘ARR’ in non-descending order with help of the merge sort algorithm.

Example :

Merge Sort Algorithm - Merge sort is a Div...read more
Q33. Ways To Make Coin Change

You are given an infinite supply of coins of each of denominations D = {D0, D1, D2, D3, ...... Dn-1}. You need to figure out the total number of ways W, in which you can make a change fo...read more

Frequently asked in,
Q34. Reverse Words in a String

You are given a string of length N. You need to reverse the string word by word. There can be multiple spaces between two words and there can be leading or trailing spaces but in the ou...read more

Q35. Left View Of Binary Tree

Given a binary tree. Print the Left View of the Tree.

Example :
If the input tree is as depicted in the picture: 

alt text

The Left View of the tree will be: 2 35 2 
Input format :
Elements in t...read more
Q36. Wildcard Pattern Matching

Given a text and a wildcard pattern of size N and M respectively, implement a wildcard pattern matching algorithm that finds if the wildcard pattern is matched with the text. The matchi...read more

Ans.

The task is to implement a wildcard pattern matching algorithm that checks if a given wildcard pattern matches a given text.

  • The wildcard pattern can include the characters '?' and '*'

  • '?' matches any single character

  • '*' matches any sequence of characters (sequence can be of length 0 or more)

  • The matching should cover the entire text, not partial text

  • Implement a function that takes the wildcard pattern and the text as input and returns True if the text matches the pattern, False...read more

Q37. Idempotent Matrix

Given a N * N matrix and the task is to check matrix is idempotent matrix or not.

See the sample input.

Idempotent matrix M follows the following property :

M*M = M 
Input format :
Line 1 : Siz...read more
Q38. Missing Number

You are given an array/list ‘BINARYNUMS’ that consists of ‘N’ distinct strings which represent all integers from 0 to N in binary representation except one integer. This integer between 0 to ‘N’ w...read more

Q39. Nth Fibonacci Number

Nth term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula -

 F(n) = F(n-1) + F(n-2), Where, F(1) = F(2) = 1 

Provided N you have to find out the ...read more

Frequently asked in, ,
Q40. Topological Sort

You are given a directed acyclic graph. Your task is to find any topological sorting of the graph.

A directed acyclic graph is a directed graph with no directed cycles.

Topological sorting for D...read more

Q41. Water Jug Problem

You are given two water jugs with capacities X and Y litres respectively. Both the jugs are initially empty. There is an infinite amount of water supply available. The jugs do not have markings...read more

Q42. Print Permutations

Given an input string (STR), print all possible permutations of the input string.

Note:
The input string may contain the same characters, so there will also be the same permutations. The order...read more
Q43. Boolean Matrix

Given a 2-dimensional boolean matrix mat of size N x M, modify the matrix such that if an element is 1, set its entire row and column to 1 i.e. if mat[i][j] = 1, then make all the elements of the ...read more

Q44. Cycle Detection in a Singly Linked List

You have given a Singly Linked List of integers, determine if it forms a cycle or not.

A cycle occurs when a node's next points back to a previous node in the list. The li...read more

Frequently asked in,
Q45. SQL Questions

Write a query to find names of the customers who have purchased less than or equal to one product. Order the output by customer name. Given customer table with customer id and customer name , produ...read more

Q46. Arithmetic Operators

Given an arithmetic expression ‘EXP’ containing integer values separated by any of the three operators ‘ + ’, ‘ - ’ and ‘ * ’. You need to place parentheses in the given expression such that...read more

Q47. Minimum Number of Platform Needed

You are given the arrival and departure times of N trains at a railway station in a day. You need to find the minimum of platforms required for the railway station such that no ...read more

Q48. Left Rotations of An Array

You are given an array consisting of 'N' elements and you need to perform 'Q' queries on the given array. Each query consists of an integer which tells the number of elements by which...read more

Q49. Matrix Multiplication

Ninja has been given two sparse matrices ‘MAT1’ and ‘MAT2’ of integers having size ‘N’ x ‘M’ and ‘M’ x ‘P’, respectively.

A sparse matrix is a matrix that contains very few non-zero element...read more

Q50. Sudoku

You are given a 9x9 sudoku. Your task is to solve sudoku and return the solution.

A sudoku is a puzzle in which players insert the numbers one to nine into a grid consisting of nine squares subdivided int...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.7k 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