SDE

30+ SDE Interview Questions and Answers for Freshers

Updated 5 Oct 2024
search-icon

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

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

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

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

Are these interview questions helpful?

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

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

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. Design a system for finding the costliest element always whenever we pick up an element from a box.(concept of Max Heap)

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

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

SDE Jobs

SDE 3-6 years
M2P
3.6
Chennai

Q9. Write a program to show whether a graph is a tree or not using adjacency matrix

Ans.

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

Q10. Describe transaction process in detail if we want to transfer from one account to other. Also design scheme for it

Ans.

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

Q11. What are the differences between graph and tree?

Ans.

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

Q12. Explain the approach of LRU cache and implement using object oriented language

Ans.

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

Q13. What is the definition of tree ?

Ans.

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

Q14. When can you say a graph to be a tree?

Ans.

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.

Q15. What happens when we type amazon.com ?

Ans.

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.

Q16. What is the meaning of memory leakage?

Ans.

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

Q17. Can you explain the concept of keys in database management systems?

Q18. How will you fix code which is working properly ?

Ans.

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

Q19. Describe ACID properties in detail

Ans.

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

Q20. What is OOPs? And its properties

Ans.

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.

Q21. write code for bfs and dfs.. explain prims algorithm

Ans.

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

Q22. Fibonacci series using dp and recursion

Ans.

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

Q23. java final and finally difference

Ans.

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.

Q24. What is your main language for program

Ans.

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.

Q25. DSA problem of DP and recursion

Ans.

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

Q26. implement insertion sort

Ans.

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

Q27. implement tree and code

Ans.

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

Q28. how would++(++i) work

Ans.

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.

Q29. Modified version of Knapsack problem

Ans.

Modified Knapsack problem

  • Similar to Knapsack problem, but with additional constraints or modifications

  • May involve multiple knapsacks or fractional items

  • Examples include 0/1 Knapsack with profit and weight limits, bounded Knapsack with item quantity limits

Q30. Trapping Rain Water problem

Ans.

Trapping Rain Water problem involves calculating the amount of water that can be trapped between walls.

  • Calculate the maximum height of water that can be trapped at each index

  • Calculate the left max height and right max height for each index

  • Subtract the current height from the minimum of left and right max heights to get the trapped water amount

Q31. SNAKE AND LADDER PROBLEM

Ans.

Snake and ladder is a classic board game where players move their tokens based on the outcome of a dice roll.

  • Players take turns rolling a dice and moving their token along the board.

  • If a player lands on a ladder, they move up to a higher-numbered square.

  • If a player lands on a snake, they move down to a lower-numbered square.

  • The first player to reach the final square wins the game.

Q32. use of namespace in c++

Ans.

Namespace in C++ is used to avoid naming conflicts and organize code.

  • Namespace allows grouping of related functions, classes, and variables.

  • It helps in avoiding naming conflicts by providing a unique identifier to each entity.

  • Namespace can be nested within another namespace.

  • Using namespace keyword, we can access the entities within a namespace.

  • Example: namespace std { class string {}; }

  • Example: using namespace std; string s;

Q33. OOPS connect in brief.

Ans.

OOPS is a programming paradigm that uses objects to represent real-world entities and their interactions.

  • OOPS stands for Object-Oriented Programming System

  • It emphasizes on encapsulation, inheritance, and polymorphism

  • Objects have attributes (data) and methods (functions)

  • Example: A car object can have attributes like color, model, and methods like start, stop

  • Classes are blueprints for creating objects

  • Inheritance allows creating a new class from an existing class

  • Polymorphism all...read more

Q34. PUZZLE PROBLEM OF GFG

Ans.

The puzzle problem of GFG involves solving a challenging puzzle on GeeksforGeeks.

  • Read the problem statement carefully and understand the requirements.

  • Break down the problem into smaller subproblems if possible.

  • Try different approaches and algorithms to solve the puzzle.

  • Test your solution with different test cases to ensure correctness.

  • Optimize your solution if possible to improve efficiency.

Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.9
 • 8.1k Interviews
4.1
 • 5k Interviews
4.0
 • 1.4k Interviews
3.7
 • 897 Interviews
4.4
 • 870 Interviews
4.0
 • 554 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

SDE 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