SDE

300+ SDE Interview Questions and Answers

Updated 5 Jul 2025
search-icon
5d ago

Q. Given an unsorted array of size 5, what is the minimum number of comparisons needed to find the median? How does this change for an array of size n?

Ans.

Minimum comparisons needed to find median in unsorted array of size n

  • For odd n, median is the middle element. For even n, median is the average of middle two elements

  • Minimum comparisons needed for odd n is (n-1)/2. For even n, it is n/2

  • Various sorting algorithms can be used to find median in an unsorted array

Asked in Adobe

6d ago

Q. Given N balls of the same weight except for one, what is the maximum value of N such that you can identify the ball with the different weight in 2 or 3 rounds of weighing?

Ans.

Determine the maximum number of balls (N) to find the lighter one in 2 or 3 weighings using a balance scale.

  • In 2 weighings, you can identify the lighter ball among 3 balls (N=3).

  • In 3 weighings, you can identify the lighter ball among 9 balls (N=9).

  • The strategy involves dividing the balls into groups and using the balance to eliminate possibilities.

  • For example, with 9 balls, divide into 3 groups of 3, weigh 2 groups, and use the result to find the lighter group.

Asked in Amazon

5d ago

Q. Write a program to determine whether a graph is a tree using an 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

Asked in Adobe

1w ago

Q. Implement a function to copy a fixed number of bytes from a source to a destination, and provide test cases. Consider scenarios where the source and destination overlap, such as copy(a, a+3, 8) or copy(a, a-4,...

read more
Ans.

Copying fixed number of bytes from source to destination and its test cases.

  • Ensure source and destination are not overlapping

  • Check if the number of bytes to be copied is greater than the available space in the destination

  • Handle cases where source or destination is NULL

  • Test cases should cover all possible scenarios including edge cases

Are these interview questions helpful?

Asked in Amazon

1w ago

Q. Given a sorted array which can have repeated elements, find the occurrence of an element. The most optimal solution is O(logn) using binary search to find the start and end occurrence.

Ans.

Given a sorted array with repeated elements, find the occurrence of a given element using binary search.

  • Use binary search to find the first occurrence of the element

  • Use binary search to find the last occurrence of the element

  • Calculate the occurrence by subtracting the indices of the last and first occurrences and adding 1

2w ago

Q. What is hashing? When is the time complexity of searching a hash table O(n)?

Ans.

Hashing is a technique to map data to a fixed-size table. Time complexity of searching a hash table is O(n) in worst case.

  • Hashing is used to store and retrieve data quickly

  • It uses a hash function to map data to a fixed-size table

  • In the best case, searching a hash table takes O(1) time

  • In the worst case, all the data maps to the same index and searching takes O(n) time

  • Collision resolution techniques like chaining and open addressing are used to handle collisions

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 Dell

6d ago
Q. What are functional relations in the context of database management systems (DBMS)?
Ans.

Functional relations in DBMS define a relationship between input and output values where each input has a unique output.

  • Functional relations ensure that each input value maps to only one output value.

  • They are commonly used in database design to enforce data integrity and consistency.

  • For example, in a table storing employee information, the employee ID can be a functional key that uniquely identifies each employee.

Asked in MiQ Digital

1d ago

Q. How many swapping operations are required to sort the array [8,22,7,9,31,19,5,13] using the bubble sort algorithm?

Ans.

The number of swaps required to sort an array using bubblesort

  • Bubble sort compares adjacent elements and swaps them if they are in the wrong order

  • Count the number of swaps required to sort the given array

  • The given array requires 19 swaps to be sorted using bubblesort

Share interview questions and help millions of jobseekers 🌟

man-with-laptop
1w ago

Q. What data structure would you use for a dictionary?

Ans.

An array of key-value pairs is the best data structure for a dictionary.

  • Use a hash table or a balanced tree to implement the dictionary.

  • Keys should be unique and immutable.

  • Values can be any data type.

  • Access time should be O(1) or O(log n) depending on the implementation.

  • Examples: Python's dict, Java's HashMap, C++'s unordered_map.

4d ago

Q. Given an array that is alternatively sorted, what is the time complexity to find an element in it? For example: 14, 3, 16, 6, 22, 7, 24, 11, 27.

Ans.

Time complexity to find an element in an alternatively sorted array.

  • The time complexity will be O(log n) using binary search.

  • Check the middle element and compare with the target element.

  • If the middle element is greater than the target, search in the left half of the array.

  • If the middle element is smaller than the target, search in the right half of the array.

  • Repeat until the target element is found or the array is exhausted.

1w ago

Q. Given three sorted arrays a, b, and c, find all pairs where a[i] + b[j] = c[k].

Ans.

Find pairs from sorted arrays a and b that sum to elements in sorted array c.

  • Use a two-pointer technique to traverse arrays a and b.

  • For each element in c, check if a[i] + b[j] equals c[k].

  • Example: a = [1, 2], b = [3, 4], c = [4, 5] results in pairs (1, 3).

  • Start with pointers at the beginning of a and b, and adjust based on the sum.

Asked in Amazon

1w ago

Q. Describe your implementation of a Least Recently Used (LRU) Cache, including your initial O(n) solution using a queue and your optimized O(1) solution using a heap and doubly linked list.

Ans.

Implementing a Least Recently Used (LRU) Cache using a combination of a doubly linked list and a hash map for O(1) access.

  • Use a hash map to store key-value pairs for O(1) access.

  • Maintain a doubly linked list to track the order of usage.

  • When accessing an item, move it to the front of the list.

  • When adding a new item, check if the cache is full; if so, remove the least recently used item from the back of the list.

  • Example: For a cache of size 2, accessing keys 1, 2, then 1 again ...read more

Asked in Facebook

2w ago

Q. How would you describe iOS manual memory management to a new developer in a few words?

Ans.

iOS manual memory management requires developers to manually allocate and deallocate memory for objects.

  • Developers must manually allocate memory for objects using methods like alloc and init.

  • Developers must also manually deallocate memory for objects using methods like release.

  • Failure to properly manage memory can lead to memory leaks and crashes.

  • ARC (Automatic Reference Counting) was introduced in iOS 5 to automate memory management.

  • However, manual memory management is still...read more

Asked in Facebook

2w ago

Q. Write a program to print the powerset. E.g. given this set {1,2,3}, it will print {},{1},{2},{3},{1,2},{1,3}, {2,3}, {1,2,3}

Ans.

Program to print powerset of a given set

  • Create an empty list to store subsets

  • Loop through all possible binary numbers from 0 to 2^n-1 where n is the length of the set

  • For each binary number, convert it to binary and use the 1's as indices to select elements from the set

  • Add the selected elements to the list of subsets

  • Return the list of subsets

Asked in Amazon

1w ago

Q. Describe the transaction process in detail for transferring funds from one account to another. Also, design a schema 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

Asked in Ameyo

2w ago

Q. How would you sort a linked list where alternate nodes are already sorted?

Ans.

Sort a linked list by nodes whose alternate nodes are already sorted.

  • Traverse the linked list and identify the alternate nodes.

  • Sort the alternate nodes using any sorting algorithm.

  • Merge the sorted alternate nodes back into the original linked list.

Asked in Amazon

1w ago

Q. In a binary tree, each node has a random pointer. If this pointer points to a node that is not a successor, set it to NULL. Otherwise, leave it untouched. Write code to implement this.

Ans.

Modify a binary tree's random pointers to point to NULL if they don't point to a successor node.

  • Traverse the binary tree using DFS or BFS.

  • For each node, check if the random pointer points to a valid successor.

  • If it points to a node that is not a successor, set it to NULL.

  • A successor of a node is defined as its children or their descendants.

Asked in Amazon

1w ago

Q. What are the differences between a graph and a 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

2d ago

Q. What is the difference between the two declarations: int p=*(int*)i; and int p=*(int*)&i;?

Ans.

The first declaration casts i to int pointer and dereferences it, while the second declaration casts the address of i to int pointer and dereferences it.

  • The first declaration assumes i is already an int pointer.

  • The second declaration takes the address of i and casts it to an int pointer.

  • The first declaration may cause a segmentation fault if i is not an int pointer.

  • The second declaration may cause unexpected behavior if i is not aligned to an int.

  • Example: int i = 42; int p = ...read more

3d ago

Q. Given an array A[n] such that A[i+1] = A[i]+1 OR A[i]-1, and a number k, find out whether k is present in A[n] or not, in the most efficient way?

Ans.

Efficiently check if a number is present in an array where each element differs by 1.

  • Use binary search to find the element in the array

  • Calculate the difference between the middle element and the first element

  • If the difference is equal to the index of the middle element minus the index of the first element, then the left half of the array is consecutive

  • If the difference is not equal, then the right half of the array is consecutive

  • Repeat the process on the appropriate half of t...read more

Asked in Amazon

2w ago

Q. Given an array and a sum s, find all pairs of numbers whose sum equals s.

Ans.

Find all unique pairs in an array that sum up to a given value s.

  • Use a hash set to track numbers we've seen. Example: For array [1, 2, 3, 4] and s=5, pairs are (1,4) and (2,3).

  • Iterate through the array, for each number x, check if (s-x) exists in the set. If yes, store the pair.

  • Ensure pairs are unique by using a set to store results. Example: For array [1, 2, 3, 2] and s=4, only (1,3) and (2,2) are valid.

  • Consider edge cases like empty arrays or no valid pairs. Example: For ar...read more

Asked in Qualcomm

1w ago

Q. How can a function from one user process be called in another user process?

Ans.

Inter-process communication mechanisms like pipes, sockets, message queues, shared memory can be used to call a function from one user process to another.

  • Use pipes to establish a unidirectional communication channel between two processes.

  • Use sockets to establish a bidirectional communication channel between two processes.

  • Use message queues to send messages between processes.

  • Use shared memory to share data between processes.

  • Remote Procedure Call (RPC) can also be used to call ...read more

Asked in Facebook

2w ago

Q. Given an expression (in single variable) like 4x+13(x-(4x+x/3)) = 9, evaluate x. The expression is a string and the variable is always x.

Ans.

Solve for x in a given expression with single variable.

  • Simplify the expression by applying the distributive property and combining like terms.

  • Isolate the variable term on one side of the equation and the constant terms on the other side.

  • Solve for x by dividing both sides of the equation by the coefficient of the variable term.

  • Check the solution by substituting the value of x back into the original equation.

  • In this case, simplify the expression to -5x/3 = -4 and solve for x to...read more

Asked in Adobe

1w ago

Q. Merge two double linked list. What will be the difference if they are singly linked list

Ans.

To merge two double linked lists, traverse to the end of the first list and connect it to the head of the second list.

  • Traverse to the end of the first list

  • Connect the last node of the first list to the head of the second list

  • If the lists are singly linked, we need to traverse to the end of the first list and connect it to the head of the second list. But we also need to keep track of the last node of the first list to connect it to the head of the second list.

  • Example: list1: ...read more

Asked in Qualcomm

2w ago

Q. How would you determine if your system is little endian or big endian?

Ans.

Endianess refers to the order in which bytes are stored in memory. Little endian stores the least significant byte first.

  • Check the byte order of a multi-byte integer value

  • Use a test value with known byte order to determine the system's endianess

  • Check the system's documentation or specifications

  • Use a code snippet to determine the endianess

6d ago

Q. A square picture is cut into 16 squares and they are shuffled. Write a program to rearrange the 16 squares to get the original big square.

Ans.

Program to rearrange shuffled 16 squares to get original big square

  • Create a 4x4 matrix to represent the big square and fill it with shuffled squares

  • Loop through the matrix and check if each square is in the correct position

  • If a square is not in the correct position, swap it with the square in the correct position

  • Repeat until all squares are in the correct position

Asked in Amazon

2w ago

Q. How do you find the kth smallest element in a BST?

Ans.

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 Qualcomm

4d ago

Q. How are function pointers shared across different processes, and which IPC mechanisms are used?

Ans.

Function pointers can be shared across processes using inter-process communication mechanisms like shared memory, pipes, sockets, etc.

  • Function pointers can be stored in shared memory regions that are accessible by multiple processes.

  • Processes can communicate with each other using pipes or sockets and pass function pointers as arguments.

  • Remote Procedure Call (RPC) mechanisms can also be used to share function pointers across processes.

  • Message Passing Interface (MPI) is another...read more

Asked in Amazon

2w ago

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

5d ago

Q. There are 9 identical marbles, one of which is heavier than the others. How do you find the heavier marble?

Ans.

Out of 9 identical marbles, find the one that is heavy.

  • Divide the marbles into groups of three

  • Weigh two groups against each other

  • If one group is heavier, weigh two marbles from that group

  • If they are equal, the heavy marble is in the third group

  • If the weighed marbles are unequal, the heavy marble is in that group

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

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