SDE

300+ SDE Interview Questions and Answers

Updated 14 Jun 2025
search-icon
3d ago

Q. Return Subsets Sum to K Problem Statement

Given an integer array 'ARR' of size 'N' and an integer 'K', return all the subsets of 'ARR' which sum to 'K'.

Explanation:

A subset of an array 'ARR' is a tuple that c...read more

Ans.

Given an array and an integer, return all subsets that sum to the given integer.

  • Use backtracking to generate all possible subsets of the array.

  • For each subset, check if the sum equals the given integer 'K'.

  • Print the subsets that satisfy the condition.

  • Example: For input [1, 2, 3] and K=3, subsets [1, 2] and [3] have sum 3.

Asked in Kellton

1d ago

Q. Partition to K Equal Sum Subsets Problem

Given an array of integers and a positive integer 'K', determine if it is possible to divide the array into 'K' non-empty subsets such that the sum of elements in each s...read more

Ans.

The problem involves dividing an array into K subsets with equal sum.

  • Use backtracking to try all possible combinations of subsets.

  • Keep track of the sum of elements in each subset and check if they are equal to the target sum.

  • Optimize by sorting the array in descending order and assigning elements to subsets greedily.

  • Handle edge cases like when the sum of elements is not divisible by K.

SDE Interview Questions and Answers for Freshers

illustration image

Asked in Nagarro

6d ago

Q. Sort a "K" Sorted Doubly Linked List

Given a doubly-linked list with N nodes, where each node’s position deviates at most K positions from its position in the sorted list, your task is to sort this given doubly...read more

Ans.

Sort a doubly linked list where each node's position deviates at most K positions from its position in the sorted list.

  • Iterate through the doubly linked list and maintain a min-heap of size K+1 to keep track of the next smallest element.

  • Remove the smallest element from the heap and add it to the sorted list. Update the heap with the next element from the removed node's next position.

  • Continue this process until all nodes are added to the sorted list.

Asked in Amazon

1d ago

Q. Describe a scenario where you were given updates on repaired road patches and had to determine the longest continuous repaired patch. What was your solution and its time complexity?

Ans.

The longest continuous patch of a road being repaired by a contractor is determined.

  • Iterate through the updates and keep track of the start and end points of each patch

  • Calculate the length of each patch and update the longest patch if necessary

  • Return the start and end points of the longest patch

Are these interview questions helpful?

Asked in Nagarro

5d ago

Q. Maximum Meetings Selection

You are tasked with scheduling meetings in a single meeting room. Given N meetings, each with a start time Start[i] and end time End[i], determine the maximum number of meetings that ...read more

Ans.

Given start and end times of meetings, find the maximum number of meetings that can be scheduled in a single room.

  • Sort the meetings based on their end times in ascending order.

  • Iterate through the sorted meetings and select the ones that do not overlap with the previously selected meetings.

  • Keep track of the selected meetings and return their indices.

Asked in Amazon

4d ago

Q. Longest Increasing Subsequence Problem Statement

Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more

Ans.

Find the length of the longest strictly increasing subsequence in an array of integers.

  • Use dynamic programming to keep track of the longest increasing subsequence ending at each element.

  • Initialize an array to store the length of the longest increasing subsequence ending at each index.

  • Iterate through the array and update the length of the longest increasing subsequence for each element.

  • Return the maximum value in the array as the length of the longest increasing subsequence.

SDE Jobs

SDE 3-10 years
Amazon Development Centre (India) Pvt. Ltd.
4.0
Chennai
SDE 1-3 years
Cue-Math Pvt.Ltd
3.7
Bangalore / Bengaluru
SDE 1-3 years
BankBazaar
3.3
Chennai

Asked in Nagarro

3d ago

Q. Duplicate Subtrees Problem Statement

Given a binary tree, return the root values of all duplicate subtrees. Two subtrees are considered duplicate if they have the same structure with identical node values. For ...read more

Ans.

Find root values of duplicate subtrees in a binary tree.

  • Traverse the tree in a bottom-up manner to identify duplicate subtrees.

  • Use a hashmap to store the subtree structures and their frequencies.

  • Return the root values of duplicate subtrees based on hashmap entries.

Asked in Nagarro

2d ago

Q. Merge k Sorted Linked Lists

You are provided with 'K' sorted linked lists, each sorted in increasing order. Your task is to merge all these lists into one single sorted linked list and return the head of the re...read more

Ans.

Merge k sorted linked lists into one single sorted linked list.

  • Create a min-heap to store the heads of all linked lists.

  • Pop the smallest element from the heap and add it to the result list.

  • If the popped element has a next element, push it back to the heap.

  • Repeat until all elements are merged into a single sorted list.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Asked in Amazon

5d ago

Q. Given n nuts and n bolts represented in two different arrays and a function is_fit(nut_i, bolt_j) which returns 0 if it's perfectly fit, 1 if it’s a tight fit and -1 if it's a loose fit, arrange them so that ev...

read more
Ans.

Arrange nuts and bolts so that every nut fits perfectly with the bolt in the same position.

  • Sort both arrays in the same order using a comparison function

  • Use a binary search to find the matching bolt for each nut

  • Repeat until all nuts are matched with bolts

Asked in Samsung

4d 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 - prev, current, and next - to keep track of the nodes while reversing the linked list.

  • Update the head of the reversed linked list as the last node encountered during reversal.

Asked in Amazon

3d ago

Q. Count Inversions Problem Statement

Given an integer array ARR of size N containing all distinct values, determine the total number of inversions present in the array.

An inversion is defined for a pair of integ...read more

Ans.

Count the total number of inversions in an integer array.

  • Iterate through the array and for each pair of elements, check if the conditions for inversion are met.

  • Use a nested loop to compare each element with all elements to its right.

  • Keep a count of the inversions found and return the total count at the end.

Asked in Facebook

5d ago

Q. Given a hashmap M which is a mapping of characters to arrays of substitute characters, and an input string S, return an array of all possible mutations of S (where any character in S can be substituted with one...

read more
Ans.

Given a hashmap M and an input string S, return an array of all possible mutations of S using M's substitutes.

  • Iterate through each character in S and get its substitutes from M

  • Use recursion to generate all possible combinations of substitutes for each character

  • Time complexity: O(n^m) where n is the average number of substitutes per character and m is the length of S

  • Space complexity: O(n^m) due to the number of possible combinations

  • Optimization: Use memoization to store previo...read more

Asked in Infosys

6d ago

Q. Bipartite Graph Problem

Check whether a given graph is bipartite or not. Return true if the graph's vertices can be divided into two independent sets, ‘U’ and ‘V’, such that every edge (‘u’, ‘v’) either connect...read more

Ans.

Check if a given graph is bipartite by dividing vertices into two independent sets.

  • Use BFS or DFS to traverse the graph and assign colors to vertices to check for bipartiteness.

  • If an edge connects vertices of the same color, the graph is not bipartite.

  • Return true if all edges connect vertices of different colors, else return false.

5d ago

Q. Boundary Traversal of Binary Tree

Given a binary tree of integers, your task is to print the boundary nodes of the binary tree in an anti-clockwise direction starting from the root node.

Note:
The boundary incl...read more
Ans.

Boundary traversal of a binary tree in anti-clockwise direction starting from the root node.

  • Implement a function to calculate the boundary traversal of a binary tree

  • Include nodes from left boundary, leaf nodes, and right boundary in sequence

  • Ensure only unique nodes are included in the output

  • Print the boundary nodes separated by single spaces for each test case

Asked in Amazon

2d ago

Q. Consider a snakes and ladders game on an n x n matrix. Starting from the initial position, what is the number of ways to reach the n-square position, given that your next move depends on the roll of a dice? You...

read more
Ans.

Calculate the number of ways to reach the end of a snakes and ladders board using dice rolls and ladders.

  • The board is represented as an n x n matrix, where each cell corresponds to a position.

  • You start at position 1 and aim to reach position n^2.

  • Each dice roll can result in moving 1 to 6 steps forward.

  • Ladders allow you to jump from one position to another, effectively skipping some cells.

  • Use dynamic programming to count the number of ways to reach each cell based on previous ...read more

Asked in Amazon

2d ago

Q. A stream of data is coming. Maintain records in a page and mechanism to see previous and next page. (Concept of Doubly Linked List) (It is always advisable to ask questions in design questions. The interviewers...

read more
Ans.

A thread is a unit of execution within a process that can run independently and concurrently with other threads.

  • Threads allow for concurrent execution of tasks within a program.

  • Threads share the same memory space and resources of the process they belong to.

  • Threads can communicate and synchronize with each other through shared data structures like locks and semaphores.

  • Threads can improve performance by utilizing multiple CPU cores or by handling I/O operations asynchronously.

  • E...read more

Asked in Facebook

6d ago

Q. Given a list of integer numbers, a list of symbols [+,-,*,/], and a target number N, provide an expression which evaluates to N or return False if that is not possible. For example, if the list of numbers is [1...

read more
Ans.

Given a list of numbers and symbols, provide an expression that evaluates to a target number.

  • Use recursion to try all possible combinations of numbers and symbols

  • Check for division by zero and negative numbers

  • Return False if no expression evaluates to the target number

Asked in Amazon

4d ago

Q. How can you measure the time between a user typing "Amazon.com" and the page appearing in their browser?

Ans.

Measure the time from typing a URL to page load using network requests and timestamps.

  • Use browser developer tools to monitor network requests and timestamps.

  • Implement a JavaScript function to capture the time when the URL is entered.

  • Send a dummy request after the page load to measure response time.

  • Utilize performance APIs like 'performance.now()' for precise timing.

  • Log the time taken for DNS resolution, TCP connection, and page rendering.

Asked in Ameyo

3d ago

Q. Given a sorted array A of size m+n, where the first m elements are filled with sorted elements, and another sorted array B of size n, merge the elements of B into A such that A contains all m+n elements in sort...

read more
Ans.

Merge two sorted arrays into one sorted array with one traversal.

  • Use two pointers to track the current elements in arrays A and B.

  • Compare the elements at the current pointers and insert the smaller one into array A.

  • Move the pointer of the array from which the smaller element was inserted.

  • Repeat the above steps until all elements are merged into array A.

Asked in MiQ Digital

1d ago

Q. Find the number of leaf nodes in a binary tree with 4 internal nodes.

Ans.

A binary tree with 4 internal nodes has 5 leaf nodes.

  • A binary tree with n internal nodes has n+1 leaf nodes.

  • A leaf node is a node with no children.

  • Count the number of leaf nodes to find the answer.

Asked in MiQ Digital

1d ago

Q. Given the preorder traversal of a tree is DEBFGCA and the postorder traversal of the tree is ABDECFG, find the inorder traversal.

Ans.

Given preorder and postorder traversal, find inorder traversal of a binary tree.

  • The last element of postorder traversal is the root of the tree

  • Find the root in preorder traversal and divide the tree into left and right subtrees

  • Recursively find the inorder traversal of left and right subtrees

  • Combine the inorder traversal of left subtree, root, and inorder traversal of right subtree

Asked in Amazon

3d ago

Q. Write an efficient program to count the number of tree structures that can be made using n number of nodes. Basically T(n)=summation (T(i) * T(n-i-1)).

Ans.

The program counts the number of tree structures that can be made using n nodes.

  • Use dynamic programming to solve the problem efficiently

  • Break down the problem into subproblems and store their solutions in an array

  • Iterate through the array to calculate the number of tree structures

  • The time complexity of the program is O(n^2)

Asked in Amazon

3d ago

Q. Design a system for finding the costliest element whenever an element is picked from a box.

Ans.

Design a system using Max Heap to find the costliest element from a box when an element is picked.

  • Implement a Max Heap data structure to store the elements in the box.

  • Whenever an element is picked, the costliest element can be found at the root of the Max Heap.

  • After picking an element, update the Max Heap by removing the root and reorganizing the heap.

  • Ensure the Max Heap property is maintained during insertion and deletion operations.

  • Example: If the box contains elements [5, ...read more

Asked in Amazon

3d ago

Q. What happens on server side on receiving HTTP requests and how operating system interacts and then discussion related with threading, thread pool ,synchronization, hashing etc

Ans.

When a server receives an HTTP request, it interacts with the operating system, handles threading, thread pooling, synchronization, and hashing.

  • Upon receiving an HTTP request, the server creates a new thread to handle the request.

  • The operating system manages the allocation of system resources to the server process.

  • Thread pooling is used to efficiently manage and reuse threads for handling multiple requests.

  • Synchronization mechanisms like locks or semaphores are used to ensure...read more

Asked in Amazon

3d ago

Q. Design a data structure and implement an algorithm to print all the files in a directory, including sub-directories. What data structure and algorithm did you use, and why?

Ans.

Implement a data structure and algorithm to print all files in a directory, including sub-directories.

  • Use an n-ary tree or stack to represent the directory structure

  • Implement a BFS or DFS algorithm to traverse the directory and print files

  • Handle sub-directories recursively

  • Consider using a queue or stack to keep track of directories to visit

Asked in Nagarro

3d ago
Q. Can you explain the concept of keys in database management systems?
Ans.

Keys in database management systems are unique identifiers for rows in a table.

  • Keys ensure data integrity by enforcing uniqueness and relationships between tables.

  • Primary key uniquely identifies each record in a table (e.g. employee ID).

  • Foreign key establishes a link between two tables by referencing the primary key of another table.

4d ago

Q. Given a 2D array of 0s and 1s where each row is sorted, find the row with the maximum number of 1s in minimum time complexity.

Ans.

Find row with maximum 1s in a sorted 2D array of 0s and 1s.

  • Use binary search to find the first occurrence of 1 in each row.

  • Calculate the number of 1s in each row using the index found in step 1.

  • Keep track of the row with maximum number of 1s.

  • Time complexity: O(m log n), where m is the number of rows and n is the number of columns.

1d ago

Q. Given an array of non-negative integers, where each element represents the maximum number of steps that can be taken forward from that element, find the minimum number of jumps to reach the end of the array. If...

read more
Ans.

Find minimum number of jumps required to reach end of array with max moves in right direction at each index.

  • Use dynamic programming approach to solve the problem

  • Maintain an array to store minimum number of jumps required to reach each index

  • Traverse the array and update the minimum number of jumps for each index

  • Return the minimum number of jumps required to reach the end of array

Asked in Ameyo

1d ago

Q. How do you retrieve the mth element from a stack containing n elements (where n > m) without using an additional stack?

Ans.

To get the mth element of a stack with n elements, without using another stack.

  • Create a temporary variable to store the mth element

  • Pop the top (n-m) elements from the stack and discard them

  • Pop and store the mth element in the temporary variable

  • Push back the discarded elements to the stack

  • Return the temporary variable as the result

Asked in Qualcomm

3d ago

Q. Write a program with 2 threads. One thread should print even numbers, and the other should print odd numbers in sequence. How would you make it SMP safe?

Ans.

Program with 2 threads printing even and odd numbers in sequence. How to make it SMP safe?

  • Use mutex locks to ensure only one thread accesses the shared resource (the number to be printed) at a time

  • Use condition variables to signal when it's safe for the other thread to access the shared resource

  • Use atomic variables to ensure that the shared resource is accessed atomically

  • Use thread-safe data structures to store the shared resource

  • Use thread-local storage to avoid contention b...read more

1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

3.6
 • 11k Interviews
3.8
 • 8.6k Interviews
3.6
 • 7.9k Interviews
4.0
 • 5.3k Interviews
3.9
 • 1.4k Interviews
View all
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

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

SDE Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
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
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
Contribute to help millions!
Write a review
Share interview
Contribute salary
Add office photos
Add office benefits