SDE
300+ SDE Interview Questions and Answers

Asked in Amazon

Q. Given a number of pairs of parentheses, find all possible valid and unique combinations without any duplicates. Write code to generate these combinations.
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

Q. Given a set of 2D points and an integer k, find the k points closest to the origin (0,0).
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

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

Q. How does Facebook implement graph search?
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'.

Asked in Facebook

Q. Explain Hadoop and its applications.
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

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




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

Asked in Amazon

Q. Describe a sliding window problem where you minimized the partial sum of the array.
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

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

Q. Convert a string of Roman numerals to an integer in O(n) time
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

Asked in Applied Materials

Q. Add mathematical operators to make all these expressions true.
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

Q. Describe an algorithm to find the top 10 trending words inserted by users on sites like Twitter.
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

Q. Find the second largest element in an array.
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

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. Write an efficient code to find the first occurrence of 1 in a sorted binary array.
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

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 Amazon

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

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

Q. Design a data structure to dynamically store an image.
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.

Asked in Microsoft Corporation

Q. Find the two largest elements in an array with O(n+log(n)) comparison.
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

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

Asked in Caterpillar Inc

Q. What is the concept of counting the number of islands in a given grid?
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

Q. How do you develop the frontend and backend for seamless data flow?
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

Q. What is Babel and how does it work?
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

Asked in Cognam Technologies

Q. Can you provide examples of where a stack data structure is used?
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

Q. What data structure would you use to store phone numbers alongside names?
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

Q. Design BookMyShow, focusing on the design of the seat matrix.
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

Q. Find the first occurrence of 1 in a sorted infinite binary array.
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

Q. How was your college life, and what activities were you involved in?
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
Interview Experiences of Popular Companies





Top Interview Questions for SDE Related Skills



Reviews
Interviews
Salaries
Users

