Amazon
40+ Interview Questions and Answers
Given a singly linked list of integers. Your task is to return the head of the reversed linked list.
For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse...read more
Given two strings, 'S' and 'T' with lengths 'M' and 'N', find the length of the 'Longest Common Subsequence'.
For a string 'str'(per se) of length K, the subsequences are the strings c...read more
Given a singly linked list of integers. Your task is to return the head of the reversed linked list.
For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked li...read more
You are given a bag of size 'W' kg and provided with the costs of packets with different weights of oranges as a list/array with the name 'cost'. Every i-th position in the cost denot...read more
You are given a Singly Linked List which contains a series of integers separated by ‘0’.
Between two zeroes, you have to merge all the nodes lying between them into a single node which contain...read more
You have been given 'N' ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. We need to conn...read more
Q7. You have given 10 files and you have given a string suggest data structure which ll facilitate efficient search of string in the file if string appears more than ones in that case u have to print line number an...
read moreSuggest a data structure for efficient search of a string in 10 files and print line number and file if string appears more than once.
Use a hash table to store the file name and line number of each occurrence of the string.
Iterate through each file and for each line, check if the string is present and update the hash table accordingly.
Print the hash table entries for the string.
1) Explain DNS
2) What is DHCP
3) What is SIP protocol
4) Difference between TCP/UDP
5) Difference between HTTP/HTTPs
6) What is proxy server.
7) Some basics Linux commands
8) What is BCNF in DBMS.
Q9. Given a binary tree in which the node structure has an additional field called “next” which of pointer to tree node type, fill up this field of each node to point to the next node at the same level (NULL if las...
read moreThe task is to fill the 'next' field of each node in a binary tree to point to the next node at the same level.
Use a level order traversal to process the tree nodes.
Maintain a queue to store the nodes at each level.
For each node, set its 'next' field to the next node in the queue.
If a node is the last node at its level, set its 'next' field to NULL.
Q10. there is an infinite stair case and there are n rounds. in i'th round we can jump i steps at one or discard them. it is given that k'th step is broken , find the max height we can reach with out stepping on the...
read moreGiven an infinite staircase with a broken kth step, find the maximum height we can reach in n rounds of jumping i steps.
We can start by jumping the maximum number of steps in each round until we reach the broken step.
After reaching the broken step, we can discard the i steps that would land us on the broken step and jump the remaining steps.
We can continue this pattern until we reach the maximum height we can reach without stepping on the broken step.
Q11. You have a dictionary of words. Given a word, print all anagram are in dictionary . State the data structure to be used to solve this problem
To find anagrams of a given word in a dictionary, use a hash table to store sorted versions of each word as keys and their corresponding original words as values.
Create a hash table to store the anagrams
Iterate through each word in the dictionary
Sort the characters of the word and use it as a key in the hash table
If the key already exists, add the word to the list of values for that key
Print the list of values for the given word's sorted characters
Q12. find the nearest greater value of a given value in a BST
Find the nearest greater value of a given value in a Binary Search Tree (BST).
Start from the root node and compare the given value with the current node's value.
If the given value is less than the current node's value, move to the left subtree.
If the given value is greater than the current node's value, move to the right subtree.
Keep track of the closest greater value encountered while traversing the tree.
Return the closest greater value found.
Q13. Given a string of parenthesis, write a function if it is balanced
Function to check if a string of parenthesis is balanced
Use a stack to keep track of opening parenthesis
If a closing parenthesis is encountered, pop from stack and check if it matches
If stack is empty and a closing parenthesis is encountered, return False
If all parenthesis are matched and stack is empty, return True
Tell the ACID properties in DBMS.
Q15. Find the number of occurrences of words in a paragraph
Count the occurrences of words in a paragraph.
Split the paragraph into words using whitespace as a delimiter.
Create a dictionary to store the count of each word.
Iterate through the words and increment the count in the dictionary.
Return the dictionary with the word counts.
Q16. Find common elements out of two sorted array?
Find common elements out of two sorted array
Use two pointers to traverse both arrays simultaneously
Compare elements at each pointer and move the pointer of the smaller element
If elements are equal, add to common elements list and move both pointers
Stop when either pointer reaches end of array
Q17. Given a csv file with users and the websites they visited, find the top k most visited website patterns by users
Use a combination of sliding window and hashmap to find top k most visited website patterns by users
Parse the csv file to extract user and website data
Use a sliding window to generate all possible website patterns for each user
Use a hashmap to count the frequency of each website pattern
Sort the website patterns based on frequency and return the top k patterns
Q18. boundary traversal of a tree
Boundary traversal of a tree is the process of visiting the nodes on the boundary of a tree in a specific order.
The boundary traversal can be done in three steps: left boundary, leaf nodes, and right boundary.
For the left boundary, start from the root and traverse down the left side of the tree until reaching a leaf node.
For the leaf nodes, perform an inorder traversal to visit all the leaf nodes of the tree.
For the right boundary, start from the rightmost leaf node and trave...read more
Q19. Convert BST to a Doubly linked list?
Convert a Binary Search Tree to a Doubly Linked List.
Create a DLL node class with left, right, and data fields.
Traverse the BST in-order and add each node to the DLL.
Adjust the left and right pointers of each node to create the DLL.
Return the head of the DLL.
Q20. Cant say because of NDA, make a package dependency ood.
Create a package dependency diagram based on object-oriented design principles.
Identify the main classes/modules in the system
Determine the relationships between classes/modules (e.g. inheritance, composition, aggregation)
Visualize the dependencies between classes/modules using arrows or lines
Consider using UML diagrams to represent the package dependency
Q21. Balanced Parenthesis No of brackets to make balanced parenthesis Maximum Units on a truck
The question is about balanced parenthesis and finding the maximum units on a truck.
To check if a string of brackets is balanced, we can use a stack data structure.
To find the maximum units on a truck, we need to sort the items by weight and then start adding them to the truck until it reaches its maximum capacity.
Q22. 1. A variation of nodes at a distance of K
A question about finding nodes at a distance of K from a given node in a graph.
Use BFS or DFS to traverse the graph and keep track of the distance from the starting node.
Maintain a visited set to avoid revisiting nodes.
Return all nodes at distance K from the starting node.
Example: Find all nodes at distance 2 from node A in a graph.
Q23. Linked list and operations for array on linked list
Linked list is a data structure where each element points to the next element. Operations like insertion, deletion, traversal can be performed on linked lists.
Linked list is a linear data structure where elements are stored in nodes. Each node contains data and a reference to the next node.
Operations on linked list include insertion, deletion, traversal, and searching.
For example, to insert a new node at the beginning of a linked list, create a new node with the data and poin...read more
Q24. Graph problems with popular algo implementations
Graph problems and popular algo implementations
Shortest Path: Dijkstra's, Bellman-Ford, Floyd-Warshall
Minimum Spanning Tree: Prim's, Kruskal's
Topological Sorting: Kahn's, DFS
Max Flow: Ford-Fulkerson, Edmonds-Karp
Travelling Salesman Problem: Held-Karp, Christofides
Graph Coloring: Greedy, Backtracking
Q25. DSA question. Detect Symmetric Binary tree.
Detect if a binary tree is symmetric.
Check if the left and right subtrees are mirror images of each other.
Use a recursive approach to compare corresponding nodes.
Base case: if both nodes are null, return true.
If one node is null and the other is not, return false.
If the values of the nodes are not equal, return false.
Recursively check if the left subtree of the left node is symmetric to the right subtree of the right node.
Recursively check if the right subtree of the left nod...read more
Q26. DSA only with higher difficulty with SDE3.
The question is about advanced data structures and algorithms for a senior software engineer role.
Focus on advanced data structures like AVL trees, B-trees, and tries
Discuss complex algorithms like Dijkstra's algorithm, A* search algorithm, and dynamic programming
Highlight experience with optimizing time and space complexity
Provide examples of solving challenging coding problems or implementing complex algorithms
Q27. Merge point of twi linked list.
Finding the merge point of two linked lists.
Traverse both linked lists to find their lengths.
Move the pointer of the longer list ahead by the difference in lengths.
Iterate both lists simultaneously until the merge point is found.
Q28. How to traverse a linked list
Traversing a linked list involves iterating through each node starting from the head until the end is reached.
Start at the head node
Iterate through each node by following the 'next' pointer until the end is reached
Perform desired operations on each node as needed
Q29. 1. DP + Sliding window problem
DP + Sliding window problem
Dynamic Programming (DP) is a technique to solve optimization problems by breaking them down into smaller subproblems
Sliding window is a technique to solve problems by maintaining a window of elements in an array or string
Combining DP and sliding window can be useful in solving problems that require both techniques
Q30. find treasury island DFS 2D array
Treasury Island can be found using Depth First Search on a 2D array of strings.
Implement a Depth First Search algorithm to traverse the 2D array of strings
Start from a specific point on the island and explore all possible paths
Keep track of visited cells to avoid infinite loops
Return the path that leads to the treasury on the island
Q31. Sum on node in binary tree
Recursively sum the values of nodes in a binary tree
Use a recursive function to traverse the tree and add the values of each node
Base case: if the current node is null, return 0
Recursive step: return the sum of current node value, left subtree sum, and right subtree sum
Q32. How to design amazon
Designing Amazon involves creating a user-friendly e-commerce platform with a vast product selection, efficient search and recommendation algorithms, secure payment processing, and reliable delivery logistics.
Develop a user-friendly interface for easy navigation and product search
Implement recommendation algorithms based on user behavior and preferences
Integrate secure payment processing systems to protect customer information
Establish efficient delivery logistics for timely ...read more
Q33. how to invert 25 bst
To invert a binary search tree (BST), swap the left and right children of each node recursively.
Start from the root node and recursively swap the left and right children of each node.
Repeat this process for all nodes in the BST.
The final result will be the inverted BST.
Q34. create a minesweeper game
Create a classic minesweeper game with a grid of cells to uncover without hitting any mines.
Create a grid of cells with hidden mines randomly placed
Allow the player to uncover cells and reveal numbers indicating nearby mines
Implement logic to end the game if a mine is uncovered or all non-mine cells are revealed
Q35. Reverse a linked list
Reverse a linked list
Iterate through the linked list and change the direction of the pointers
Use three pointers to keep track of current, previous and next nodes
Recursively reverse the linked list
Q36. Number of Islands (on lc)
Count the number of islands in a 2D grid where '1' represents land and '0' represents water.
Iterate through the grid and for each '1' encountered, perform a depth-first search to mark all adjacent '1's as visited.
Increment the island count for each new island found.
Ensure to handle boundary conditions and visited cells properly to avoid infinite loops.
Q37. sort linked lists
Sorting linked lists involves rearranging the nodes in a specific order.
Use a sorting algorithm such as merge sort or quick sort to rearrange the nodes in the linked list.
Iterate through the linked list and compare each node with the next one to determine the correct order.
Consider the time complexity of the sorting algorithm to ensure efficient sorting of the linked list.
Q38. bus transit system design
Designing a bus transit system involves planning routes, schedules, stops, and ticketing systems.
Consider the population density and traffic patterns of the area to determine the number and frequency of bus routes.
Create a network of bus stops strategically located near residential areas, commercial centers, and transportation hubs.
Implement a reliable ticketing system that allows for cashless payments and offers options for daily, weekly, and monthly passes.
Integrate real-ti...read more
Q39. Subsequences of arrays
Subsequences of arrays are all possible combinations of elements in an array.
A subsequence can be of any length, including 0 and the entire array.
The order of elements in a subsequence must be maintained.
The number of possible subsequences of an array of length n is 2^n.
For example, the subsequences of [1, 2, 3] are [], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3].
Q40. Troubleshoot a problem
To troubleshoot a problem, identify the issue, gather information, analyze data, and implement a solution.
Identify the problem by asking questions and gathering information
Analyze data to determine the root cause of the problem
Implement a solution by testing and verifying the fix
Document the problem and solution for future reference
Q41. Merge sort implementation
Merge sort is a divide and conquer algorithm that divides the input array into two halves, sorts them, and then merges them back together.
Divide the array into two halves recursively
Sort each half using merge sort
Merge the sorted halves back together
More about working at Amazon
Top HR Questions asked in null
Interview Process at null
Top Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month