SDE
40+ SDE Interview Questions and Answers for Freshers

Asked in Kellton

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

Asked in Nagarro

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
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 Nagarro

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
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 Nagarro

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

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

Asked in Amazon

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 moreA 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
SDE Jobs




Asked in Amazon

Q. Design a system for finding the costliest element whenever an element is picked from a box.
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

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
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
Share interview questions and help millions of jobseekers 🌟

Asked in Nagarro

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.

Asked in Amazon

Q. Write a program to determine whether a graph is a tree using an adjacency matrix.
Program to determine if a graph is a tree using adjacency matrix
A graph is a tree if it is connected and has no cycles
Check if the graph is connected by performing a depth-first search or breadth-first search
Check if the graph has cycles by performing a depth-first search and tracking visited nodes

Asked in Amazon

Q. Describe the transaction process in detail for transferring funds from one account to another. Also, design a schema for it.
The transaction process involves transferring funds from one account to another. A scheme is designed to ensure secure and accurate transfers.
Verify the availability of sufficient funds in the sender's account
Authenticate the sender's identity and authorization for the transaction
Deduct the transfer amount from the sender's account balance
Initiate a request to transfer the funds to the recipient's account
Validate the recipient's account details
Add the transferred amount to th...read more

Asked in Amazon

Q. What are the differences between a graph and a tree?
Graphs are non-linear data structures with cycles while trees are hierarchical data structures without cycles.
Graphs can have cycles while trees cannot
Graphs can have multiple root nodes while trees have only one
Graphs can have disconnected components while trees are always connected
Graphs can have directed or undirected edges while trees have only directed edges
Examples of graphs include social networks, road networks, and computer networks while examples of trees include fi...read more

Asked in Amazon

Q. How do you find the kth smallest element in a BST?
To find kth-smallest element in BST, perform inorder traversal and return the kth element.
Perform inorder traversal of the BST
Maintain a counter variable to keep track of the number of nodes visited
When the counter reaches k, return the current node's value
If k is greater than the number of nodes in the BST, return null or throw an exception

Asked in Amazon

Q. Explain the approach of LRU cache and implement using object oriented language
LRU cache is a data structure that stores most recently used items and discards least recently used items.
LRU stands for Least Recently Used
It is implemented using a doubly linked list and a hash map
When an item is accessed, it is moved to the front of the list
When the cache is full, the least recently used item is removed from the end of the list
Example: A web browser cache that stores recently visited web pages

Asked in Amazon

Q. What is the definition of a tree data structure?
A tree is a data structure consisting of nodes connected by edges, with a single root node and no cycles.
Nodes represent elements of the tree, and edges represent the relationships between them.
Each node can have zero or more child nodes, and each child node can have its own children.
Trees are commonly used in computer science for organizing and searching data, such as in binary search trees.
Examples of trees include file systems, family trees, and HTML document object models...read more

Asked in Amazon

Q. When can you say a graph is a tree?
A graph can be called a tree if it is connected and has no cycles.
A tree is a type of graph with no cycles.
It must be connected, meaning there is a path between any two vertices.
It has n-1 edges, where n is the number of vertices.
Examples include family trees, file directory structures, and decision trees.

Asked in Amazon

Q. What happens when you type amazon.com into a web browser?
Typing amazon.com in the browser's address bar takes you to Amazon's website.
The browser sends a request to the DNS server to resolve the domain name 'amazon.com' to an IP address.
The browser establishes a TCP connection with the server at the resolved IP address.
The browser sends an HTTP request to the server for the homepage of Amazon's website.
The server responds with the HTML code for the homepage, which the browser renders and displays to the user.

Asked in Amazon

Q. What is the meaning of memory leakage?
Memory leakage is a situation where a program fails to release memory it no longer needs.
Memory leakage can cause a program to slow down or crash due to insufficient memory.
It is caused by programming errors such as not freeing allocated memory or losing references to it.
Examples include forgetting to close a file or database connection, or not releasing memory allocated for a variable.
Memory leakage can be detected using memory profiling tools.
Preventing memory leakage invol...read more
Asked in Tummee.com

Q. How would you approach fixing code that is already working properly?
To fix code that is working properly, first identify the problem, analyze the code, make necessary changes, and test thoroughly.
Identify the problem by reproducing the issue and understanding the expected behavior.
Analyze the code to find any logical errors, syntax issues, or performance bottlenecks.
Make necessary changes by modifying the code, fixing bugs, optimizing algorithms, or enhancing functionality.
Thoroughly test the modified code to ensure it works as expected and d...read more

Asked in Amazon

Q. Describe ACID properties in detail
ACID properties ensure reliability and consistency in database transactions.
ACID stands for Atomicity, Consistency, Isolation, and Durability.
Atomicity ensures that a transaction is treated as a single unit of work, either all or none of its operations are executed.
Consistency ensures that a transaction brings the database from one valid state to another.
Isolation ensures that concurrent transactions do not interfere with each other, providing a sense of isolation.
Durability ...read more

Asked in ION Group

Q. What is OOPs? And its properties
OOPs stands for Object-Oriented Programming. It is a programming paradigm based on the concept of objects.
Encapsulation: Bundling data and methods that operate on the data into a single unit.
Inheritance: Ability of a class to inherit properties and behavior from another class.
Polymorphism: Ability to present the same interface for different data types.
Abstraction: Hiding the complex implementation details and showing only the necessary features.

Asked in Quantitative Brokers

Q. write code for bfs and dfs.. explain prims algorithm
BFS and DFS are graph traversal algorithms, while Prim's algorithm is used for finding minimum spanning tree in a weighted graph.
BFS (Breadth First Search) visits nodes level by level, using a queue. Example: 1->2->3->4
DFS (Depth First Search) explores as far as possible along each branch before backtracking. Example: 1->2->4->3
Prim's algorithm finds the minimum spanning tree by starting from an arbitrary node and adding the closest edge at each step. Example: A->B, B->C, C->...read more

Asked in RxLogix Corporation

Q. Fibonacci series using dp and recursion
Fibonacci series can be generated using dynamic programming and recursion.
Dynamic programming involves storing the values of previous calculations to avoid redundant calculations.
Recursion involves calling the function within itself to generate the series.
DP solution has O(n) time complexity while recursive solution has O(2^n) time complexity.
DP solution uses an array to store the values while recursive solution uses function calls.
Example DP solution: int fib[n+1]; fib[0]=0,...read more

Asked in Worldline Group

Q. What is the difference between final and finally in Java?
final is a keyword used to declare constants in Java, while finally is a block used in exception handling to ensure code execution.
final keyword is used to declare constants in Java classes or methods.
final variables cannot be reassigned once initialized.
finally block is used in exception handling to ensure code execution, regardless of whether an exception is thrown or not.

Asked in Rakuten

Q. What is your primary programming language?
My main language for programming is Java.
I have been using Java for over 5 years.
I am proficient in object-oriented programming with Java.
I have experience in developing web applications using Java frameworks like Spring and Hibernate.

Asked in Amazon

Q. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
Count the number of islands in a 2D grid of '1's (land) and '0's (water).
Use Depth-First Search (DFS) or Breadth-First Search (BFS) to explore the grid.
Mark visited land cells to avoid counting them multiple times.
Iterate through each cell; if it's '1', increment the island count and explore its neighbors.
Example: For grid [['1','1','0'], ['0','1','0'], ['0','0','0']], the output is 1.

Asked in ElasticRun

Q. DSA problem of DP and recursion
Dynamic Programming (DP) is a technique to solve problems by breaking them down into smaller subproblems and solving them recursively.
DP is used to solve optimization problems where we need to find the best solution among all possible solutions.
DP problems can be solved using either top-down (memoization) or bottom-up (tabulation) approach.
Recursion is a technique where a function calls itself to solve a problem. It is often used in DP problems.
DP and recursion are closely re...read more

Asked in Dell

Q. Implement a tree data structure and provide code.
Implementing a tree data structure using code
Define a Node class with left and right child pointers
Implement insert, search, and delete functions
Traversal methods: inorder, preorder, postorder
Examples: binary search tree, AVL tree, red-black tree

Asked in Dell

Q. Write a function to implement the insertion sort algorithm.
Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time.
Start with the second element and compare it with the first element, swap if necessary
Move to the third element and compare it with the second and first element, swap if necessary
Continue this process until the entire array is sorted
Time complexity: O(n^2)
Example: ['banana', 'apple', 'orange', 'grape'] -> ['apple', 'banana', 'grape', 'orange']

Asked in Samsung

Q. How would ++(++i) work?
The expression would increment the value of i twice before using it in the operation.
The value of i would be incremented by 2 before being used in the operation.
This is equivalent to writing i = i + 2; followed by the operation using the new value of i.
For example, if i was initially 3, the expression would evaluate to 6.
Interview Experiences of Popular Companies





Top Interview Questions for SDE Related Skills

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


Reviews
Interviews
Salaries
Users

