SDE

300+ SDE Interview Questions and Answers

Updated 13 Jul 2025
search-icon

Asked in Amazon

6d ago

Q. Given a number of pairs of parentheses, find all possible valid and unique combinations without any duplicates. Write code to generate these combinations.

Ans.

Find total possible valid unique combinations of given number of pairs of parenthesis without duplicity.

  • Use recursion to generate all possible combinations

  • Check for validity of each combination using a stack

  • Use a set to avoid duplicity

Asked in Facebook

1w ago

Q. Given a set of 2D points and an integer k, find the k points closest to the origin (0,0).

Ans.

Find k closest points to origin from a set of 2D points.

  • Calculate distance of each point from origin using distance formula

  • Sort the points based on distance in ascending order

  • Return first k points from the sorted list

Asked in Amazon

1d ago

Q. Given an in-order traversal of a special binary tree having the property that the node is always greater than its left and right child, construct the tree and write code.

Ans.

Construct a binary tree from in-order traversal with nodes greater than left and right child.

  • The root node will be the maximum value in the in-order traversal

  • Recursively construct the left and right subtrees using the left and right portions of the in-order traversal

  • Repeat until all nodes are added to the tree

Asked in Facebook

2w ago

Q. How does Facebook implement graph search?

Ans.

Facebook implements graph search by indexing user data and using natural language processing.

  • Facebook indexes user data to create a graph of connections and relationships.

  • Natural language processing is used to interpret user queries and return relevant results.

  • Graph search allows users to search for specific information within their network, such as 'friends who like hiking'.

Are these interview questions helpful?

Asked in Facebook

2w ago

Q. Explain Hadoop and its applications.

Ans.

Hadoop is a distributed computing framework used for storing and processing large datasets.

  • Hadoop is based on the MapReduce programming model.

  • It allows for parallel processing of large datasets across multiple nodes.

  • Hadoop consists of two main components: HDFS for storage and MapReduce for processing.

  • It is commonly used for big data analytics, machine learning, and data warehousing.

  • Examples of companies using Hadoop include Facebook, Yahoo, and eBay.

Asked in Google

2w ago

Q. Given a binary tree where every node value is a number, find the sum of all the numbers that are formed from root to leaf paths.

Ans.

Sum all numbers formed from root to leaf paths in a binary tree

  • Traverse the tree from root to leaf nodes, keeping track of the current number formed

  • Add the current number to the sum when reaching a leaf node

  • Recursively explore left and right subtrees

SDE Jobs

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

Asked in Amazon

2w ago

Q. What is the definition of a tree data structure?

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

Asked in Amazon

1w ago

Q. When can you say a graph is 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.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Asked in Amazon

4d ago

Q. Describe a sliding window problem where you minimized the partial sum of the array.

Ans.

Sliding window problem to minimize partial sum of array.

  • Use two pointers to maintain the window.

  • Move the right pointer to expand the window and left pointer to shrink it.

  • Keep track of the minimum partial sum seen so far.

  • Example: Given array [2, 3, 1, 2, 4, 3] and window size 3, the minimum partial sum is 6.

Asked in Amazon

1w ago

Q. Given two linked lists, one input and one output, identify the pattern between them and code the logic. The problem involves reversing the two halves of a linked list.

Ans.

Reversing two halves of a linked list problem

  • Identify input and output linked lists

  • Reverse the two halves of the input linked list

  • Compare the reversed input linked list with the output linked list

  • If they match, return true else false

Asked in Facebook

6d ago

Q. Convert a string of Roman numerals to an integer in O(n) time

Ans.

Convert Roman numerals to integer in O(n) time

  • Create a dictionary to map Roman numerals to integers

  • Iterate through the string from right to left

  • If the current numeral is less than the previous, subtract it from the total

  • Else, add it to the total

  • Return the total

5d ago

Q. Add mathematical operators to make all these expressions true.

Ans.

Add mathematical operators to make given expressions true.

  • Use addition, subtraction, multiplication, division, exponentiation, and parentheses to modify the expressions.

  • For example, 5 - 3 + 2 = 4 can be made true by adding parentheses: 5 - (3 + 2) = 0.

  • Another example is 6 6 6 6 = 4 can be made true by using square root: √6 ÷ √6 + √6 - √6 = 4.

Asked in Amazon

1w ago

Q. Describe an algorithm to find the top 10 trending words inserted by users on sites like Twitter.

Ans.

An algorithm to find top 10 trending words inserted by users in sites like Twitter.

  • Collect a large dataset of tweets

  • Tokenize the tweets into individual words

  • Remove stop words and punctuation

  • Count the frequency of each word

  • Sort the words by frequency in descending order

  • Select the top 10 words

Asked in Amazon

4d ago

Q. Find the second largest element in an array.

Ans.

Find the second largest element in an array.

  • Sort the array and return the second last element

  • Iterate through the array and keep track of the two largest elements

  • Use a priority queue to find the second largest element

Asked in Amazon

6d ago

Q. What happens when you type amazon.com into a web browser?

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.

Asked in Amazon

5d ago

Q. Write an efficient code to find the first occurrence of 1 in a sorted binary array.

Ans.

Find the first occurrence of 1 in a sorted binary array.

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

  • If the mid element is 1, check if it's the first occurrence or if the element before it is 0.

  • If the mid element is 0, search in the right half of the array.

  • If the mid element is 1 and the element before it is also 1, search in the left half of the array.

Asked in Amazon

2w ago

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

Asked in Amazon

2w ago

Q. Design a valet parking lot with the basic use-case of assigning a ticket to a customer and retrieving the car later. Three sizes are available. Use best fit and nearest distance algorithms.

Ans.

Design a valet parking lot with ticket assignment and car retrieval using best fit and nearest distance.

  • Create a parking lot with designated spots for each size of car

  • Assign a ticket to the customer upon entry and record the spot number

  • Retrieve the car by searching for the nearest available spot of the appropriate size

  • Use best fit algorithm to minimize empty spots

  • Implement a system for payment upon exit

Asked in NetApp

2w ago

Q. Given a string S and a list of words, find all starting indices of substrings in S that are formed by concatenating all words from the list.

Ans.

Use sliding window technique to find starting indices of substring formed by concatenating words from list in string S.

  • Create a hashmap to store the frequency of words in the list.

  • Use sliding window of size equal to total length of all words combined.

  • Slide the window through the string and check if the substring formed matches the hashmap.

  • If match found, store the starting index of the substring.

Asked in Adobe

2w ago

Q. Design a data structure to dynamically store an image.

Ans.

A dynamic data structure for storing images as arrays of strings.

  • Use a 2D array of strings to represent the image pixels.

  • Implement resizing methods to adjust the size of the image.

  • Include methods for adding, removing, and modifying pixels.

  • Consider using compression techniques to reduce memory usage.

  • Support various image formats such as JPEG, PNG, and BMP.

1w ago

Q. Find the two largest elements in an array with O(n+log(n)) comparison.

Ans.

Find 2 maximum elements in array in O(n+log(n)) comparison

  • Use divide and conquer approach

  • Divide array into two halves

  • Recursively find max elements in each half

  • Compare the two max elements to find the overall max elements

Asked in Amazon

2w ago

Q. Given a tree, populate the sibling of each tree node with the next node at the same level. The space complexity should be O(1).

Ans.

Populate sibling of a tree node with next node in same level with O(1) space complexity.

  • Traverse the tree level by level using BFS.

  • For each node, check if it has a sibling to its right.

  • If yes, populate the sibling pointer of the current node with the right sibling.

  • If no, move to the next level.

  • Repeat until all levels are traversed.

1w ago

Q. What is the concept of counting the number of islands in a given grid?

Ans.

Counting the number of islands in a grid involves identifying connected groups of '1's in a 2D matrix.

  • Iterate through each cell in the grid.

  • If the cell is a '1', perform a depth-first search to mark all connected '1's as visited.

  • Increment the island count for each new island found.

  • Continue until all cells have been visited.

Asked in Mercor

1w ago

Q. How do you develop the frontend and backend for seamless data flow?

Ans.

Developing frontend and backend for seamless data flow involves designing APIs, using frameworks like React and Node.js, and ensuring proper data validation and error handling.

  • Design APIs to establish communication between frontend and backend

  • Utilize frameworks like React for frontend and Node.js for backend development

  • Implement proper data validation to ensure data integrity

  • Handle errors effectively to maintain seamless data flow

Asked in Binmile

2w ago

Q. What is Babel and how does it work?

Ans.

Babel is a JavaScript compiler that converts modern JavaScript code into backward-compatible versions for different environments.

  • Babel allows developers to write code using the latest ECMAScript features without worrying about browser compatibility.

  • It transforms code written in ES6/ES7 into ES5, which is supported by older browsers.

  • Babel plugins can be used to add additional features or transform code in specific ways.

  • It can also be configured to target specific environments ...read more

2w ago

Q. Can you provide examples of where a stack data structure is used?

Ans.

Stack data structure is used in function call stack, undo mechanisms, and expression evaluation.

  • Function call stack in programming languages like C, Java, etc.

  • Undo mechanisms in text editors and software applications.

  • Expression evaluation in compilers and calculators.

Asked in ION Group

2w ago

Q. What data structure would you use to store phone numbers alongside names?

Ans.

Use a hash table to store phone numbers alongside names for quick lookups.

  • Use a hash table where the keys are the phone numbers and the values are the corresponding names.

  • This allows for constant time lookups of names based on phone numbers.

  • Example: {"555-1234": "John Doe", "555-5678": "Jane Smith"}

Asked in NoBroker

4d ago

Q. Design BookMyShow, focusing on the design of the seat matrix.

Ans.

Design a seat matrix for a ticket booking platform like BookMyShow, focusing on user experience and data management.

  • Use a 2D array to represent the seating arrangement, where each element indicates seat availability (e.g., 0 for available, 1 for booked).

  • Implement a grid layout for different sections (e.g., VIP, Regular) to allow users to choose their preferred seating area.

  • Incorporate features like seat selection, where users can click on seats to book them, updating the matr...read more

Asked in Amazon

1w ago

Q. Find the first occurrence of 1 in a sorted infinite binary array.

Ans.

Find the first occurrence of 1 in a sorted infinite binary tree.

  • Use binary search to traverse the tree.

  • If the current node is 1, check if its left child is also 1. If yes, move to the left subtree, else return the current node.

  • If the current node is 0, move to the right subtree.

  • Repeat until the first occurrence of 1 is found or the tree is exhausted.

Asked in BNY

2w ago

Q. How was your college life, and what activities were you involved in?

Ans.

My college life was a blend of academics, extracurricular activities, and personal growth, shaping my skills and friendships.

  • Participated in coding competitions, enhancing my problem-solving skills.

  • Joined the robotics club, where I collaborated on building a robot for competitions.

  • Volunteered for community service, organizing events that helped local charities.

  • Attended workshops and seminars to learn about emerging technologies.

  • Built lasting friendships through group projects...read more

Previous
1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.7
 • 8.7k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Amazon Logo
4.0
 • 5.4k Interviews
Flipkart Logo
3.9
 • 1.5k Interviews
View all
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
SDE Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
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
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits