Add office photos
Samsung logo
Employer?
Claim Account for FREE

Samsung

3.9
based on 7.2k Reviews
Video summary
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by

300+ Samsung Interview Questions and Answers

Updated 19 Feb 2025
Popular Designations

Q1. Minimum Time in Wormhole Network

Determine the minimum time required to travel from a starting point to a destination point in a two-dimensional coordinate system, considering both direct movement and the use o...read more

Ans.

Find the minimum time to travel from a starting point to a destination point using direct movement and wormholes.

  • Calculate the time taken for direct movement from source to destination.

  • Consider using each wormhole to see if it reduces the total travel time.

  • Choose the path with the minimum total time to reach the destination.

Add your answer
right arrow

Q2. Remove Consecutive Duplicates Problem Statement

For a given string str, remove all the consecutive duplicate characters.

Example:

Input:
Input String: "aaaa"
Output:
Expected Output: "a"
Input:
Input String: "a...read more
Ans.

Remove consecutive duplicate characters from a given string.

  • Iterate through the string and compare each character with the previous one.

  • If the current character is different from the previous one, add it to the result string.

  • Return the result string as the output.

Add your answer
right arrow
Samsung Interview Questions and Answers for Freshers
illustration image

Q3. Bursting Balloons Problem

Given an array ARR of size N, where each element represents the height of a balloon. The task is to destroy all balloons by shooting arrows from left to right. When an arrow hits a bal...read more

Ans.

Find the minimum number of arrows needed to burst all balloons by shooting arrows from left to right.

  • Sort the array in non-decreasing order to make it easier to calculate the minimum number of arrows needed.

  • Iterate through the sorted array and count the number of times the height decreases compared to the previous balloon.

  • The count of decreases + 1 will give the minimum number of arrows needed to burst all balloons.

  • Example: For input N = 5, ARR = [2, 3, 4, 5, 1], the minimum ...read more

Add your answer
right arrow

Q4. LCA of Binary Tree Problem Statement

You are given a binary tree consisting of distinct integers and two nodes, X and Y. Your task is to find and return the Lowest Common Ancestor (LCA) of these two nodes.

The ...read more

Ans.

Find the Lowest Common Ancestor of two nodes in a binary tree.

  • Traverse the binary tree to find the paths from the root to nodes X and Y.

  • Compare the paths to find the last common node, which is the Lowest Common Ancestor.

  • Implement a recursive function to find the LCA efficiently.

  • Handle edge cases such as when X or Y is the root node or when X or Y is not present in the tree.

Add your answer
right arrow
Discover Samsung interview dos and don'ts from real experiences

Q5. Reverse Alternate K Nodes Problem Statement

You are given a singly linked list of integers along with a positive integer 'K'. The task is to modify the linked list by reversing every alternate 'K' nodes of the ...read more

Ans.

Reverse every alternate K nodes in a singly linked list of integers.

  • Traverse the linked list in groups of K nodes and reverse every alternate group.

  • Handle cases where the number of remaining nodes is less than K.

  • Ensure to properly link the reversed groups to maintain the integrity of the linked list.

Add your answer
right arrow

Q6. Count Leaf Nodes in a Binary Tree

Count the number of leaf nodes present in a given binary tree. A binary tree is a data structure where each node has at most two children, known as the left child and the right...read more

Ans.

Count the number of leaf nodes in a binary tree where each node has at most two children.

  • Traverse the binary tree and count nodes with both children as NULL.

  • Use recursion to check each node in the tree.

  • Leaf nodes have no child nodes.

  • Example: For input 20 10 35 5 15 30 42 -1 13 -1 -1 -1 -1 -1 -1 -1, output should be 4.

Add your answer
right arrow
Are these interview questions helpful?

Q7. Explain the memory layout of main memory of computer system? Give an example to make understand the memory layout means in which segment what type of variable will be store?

Ans.

Explanation of memory layout in main memory of computer system.

  • Main memory is divided into four segments: stack, heap, data, and code.

  • Stack stores local variables and function calls.

  • Heap stores dynamically allocated memory.

  • Data stores global and static variables.

  • Code stores the program instructions.

  • Example: int x; //stored in data segment, int *p = new int; //stored in heap segment

Add your answer
right arrow

Q8. Game of Stones Problem Statement

Two players, 'Ale' and 'Bob', are playing a game with a pile of stones. Your task is to determine the winner if both play optimally.

Rules of the Game:

1. On each turn, a player...read more

Ans.

Determine the winner of a game where two players take stones alternately, with specific rules.

  • Implement a recursive function to simulate the game, considering the rules provided.

  • Check if the current player can take any stones, if not, the other player wins.

  • Return 'Ale' if 'Ale' will win the game, otherwise return 'Bob'.

Add your answer
right arrow
Share interview questions and help millions of jobseekers 🌟
man with laptop

Q9. How to divide the frequency of the clock by two?

Ans.

To divide the frequency of the clock by two, use a flip-flop circuit.

  • Use a D flip-flop or a JK flip-flop.

  • Connect the output of the flip-flop to the input of the clock signal.

  • The output of the flip-flop will be half the frequency of the input clock signal.

View 8 more answers
right arrow

Q10. Trapping Rain Water Problem Statement

You are given a long type array/list ARR of size N, representing an elevation map. The value ARR[i] denotes the elevation of the ith bar. Your task is to determine the tota...read more

Ans.

Calculate the total amount of rainwater that can be trapped between given elevations in an array.

  • Iterate through the array and calculate the maximum height on the left and right of each bar.

  • Calculate the amount of water that can be trapped above each bar by taking the minimum of the maximum heights on the left and right.

  • Sum up the trapped water above each bar to get the total trapped water for the entire array.

Add your answer
right arrow

Q11. Shortest Path in a Binary Matrix Problem Statement

Given a binary matrix of size N * M where each element is either 0 or 1, find the shortest path from a source cell to a destination cell, consisting only of 1s...read more

Ans.

Find the shortest path in a binary matrix from a source cell to a destination cell consisting only of 1s.

  • Use Breadth First Search (BFS) algorithm to find the shortest path.

  • Initialize a queue with the source cell and keep track of visited cells.

  • Explore all 4 directions from each cell and update the path length accordingly.

  • Return the shortest path length or -1 if no valid path exists.

Add your answer
right arrow

Q12. 0-1 Knapsack Problem Statement

You are tasked with determining the maximum profit a thief can earn. The thief is looting a store and can carry a maximum weight 'W' in his knapsack. There are 'N' items, each wit...read more

Ans.

The 0-1 Knapsack Problem involves maximizing profit by selecting items with known weights and values within a given weight capacity.

  • Understand the problem: Given items with weights and values, determine the maximum profit the thief can achieve within the knapsack's weight capacity.

  • Dynamic Programming: Use dynamic programming to solve the problem efficiently by considering the weight constraints and maximizing the total value.

  • Example: For input (1, 4, 10, [6, 1, 5, 3], [3, 6, ...read more

Add your answer
right arrow

Q13. Merge Two Sorted Linked Lists Problem Statement

You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.

Input:...read more

Ans.

Merge two sorted linked lists into a single sorted linked list without using additional space.

  • Create a dummy node to start the merged list

  • Compare the nodes of the two lists and link them accordingly

  • Move the pointer to the next node in the merged list

  • Handle cases where one list is empty or both lists are empty

  • Time complexity: O(n), Space complexity: O(1)

Add your answer
right arrow

Q14. Maximum Sum Path from Leaf to Root

Given a binary tree with 'N' nodes, identify the path from a leaf node to the root node that has the maximum sum among all root-to-leaf paths.

Example:

All the possible root t...read more

Ans.

Find the path from a leaf node to the root node with the maximum sum in a binary tree.

  • Traverse the binary tree from leaf to root while keeping track of the sum of each path.

  • Compare the sums of all paths and return the path with the maximum sum.

  • Use recursion to traverse the tree efficiently.

  • Consider negative values in the tree when calculating the sum of paths.

Add your answer
right arrow

Q15. Design a sequential circuit to detect a sequence 001001?Explain it?How can you reduce the minimum number of states in this design?

Ans.

Design a sequential circuit to detect the sequence 001001 and reduce the minimum number of states.

  • Use a state diagram to visualize the circuit

  • Implement the circuit using flip-flops and logic gates

  • Use Karnaugh maps to simplify the circuit

  • Consider using a Mealy or Moore machine

View 2 more answers
right arrow

Q16. Maximum Gold Collection from Gold Mine

Imagine a gold mine represented by a 2D matrix with dimensions 'N' by 'M', where 'N' is the number of rows and 'M' is the number of columns. Each cell in this matrix conta...read more

Ans.

Find the maximum amount of gold a miner can collect from a gold mine by moving right, up diagonally, or down diagonally.

  • Use dynamic programming to keep track of the maximum gold collected at each cell.

  • At each cell, consider the maximum gold collected from the cell above, below, and to the left.

  • Add the current cell's gold value to the maximum gold collected from the adjacent cells to determine the maximum gold at the current cell.

  • Repeat this process for each cell in the matrix...read more

Add your answer
right arrow

Q17. Largest Number in Binary Tree

You are provided with a Binary Tree consisting of 'N' nodes, where each node holds an integer value. Your task is to determine the largest possible number that can be formed by con...read more

Ans.

Find the largest number that can be formed by concatenating all node values in a Binary Tree.

  • Traverse the Binary Tree in a way that ensures the largest values are concatenated first.

  • Use a custom comparator function to sort the node values in descending order before concatenating.

  • Handle null nodes by skipping them during concatenation.

  • Convert integer node values to strings for concatenation.

  • Implement a recursive function to traverse the Binary Tree and concatenate node values.

Add your answer
right arrow

Q18. Delete a Given Node from Doubly Linked List

Ninja is learning about doubly linked lists and wants to remove a specified element from the list. Can you assist Ninja in doing this and returning the modified linke...read more

Ans.

Remove a specified element from a doubly linked list and return the modified list.

  • Traverse the doubly linked list to find the specified element to be removed.

  • Update the pointers of the previous and next nodes to skip the node to be deleted.

  • Handle edge cases like removing the head or tail of the linked list.

  • Return the modified linked list after removing the specified element.

Add your answer
right arrow

Q19. Find The Repeating And Missing Number Problem Statement

You are provided with an array nums which contains the first N positive integers. In this array, one integer appears twice, and one integer is missing. Yo...read more

Ans.

Given an array of first N positive integers with one number repeating and one missing, find the repeating and missing numbers.

  • Iterate through the array and keep track of the sum of elements and sum of squares to find the missing and repeating numbers.

  • Use a set to identify the repeating number and calculate the missing number based on the sum of elements.

  • Example: For nums = [1, 2, 3, 4, 4, 5], the repeating number is 4 and the missing number is 6.

Add your answer
right arrow

Q20. Convert a Binary Tree to its Sum Tree

Given a binary tree of integers, convert it to a sum tree where each node is replaced by the sum of the values of its left and right subtrees. Set leaf nodes to zero.

Input...read more

Ans.

Convert a binary tree to a sum tree by replacing each node with the sum of its left and right subtrees.

  • Traverse the tree in postorder fashion.

  • For each node, calculate the sum of its left and right subtrees and update the node value.

  • Set leaf nodes to zero.

  • Return the level order traversal of the modified tree.

Add your answer
right arrow

Q21. Gold Mine Problem Statement

You are provided with a gold mine, represented as a 2-dimensional matrix of size N x M with N rows and M columns. Each cell in this matrix contains a positive integer representing th...read more

Ans.

The task is to determine the maximum amount of gold a miner can collect by moving in allowed directions in a gold mine represented as a 2D matrix.

  • Create a 2D DP array to store the maximum gold collected at each cell

  • Iterate through the matrix from left to right and update the DP array based on the allowed directions

  • Return the maximum value in the last column of the DP array as the final result

Add your answer
right arrow

Q22. Rod Cutting Problem Statement

Given a rod of a certain length, the rod can be divided into different sizes, each with an associated cost. Your task is to determine the maximum cost that can be obtained by cutti...read more

Ans.

The Rod Cutting Problem involves maximizing the profit obtained by cutting a rod into smaller pieces and selling them.

  • Use dynamic programming to solve this problem efficiently.

  • Create a table to store the maximum profit for each sub-length of the rod.

  • Iterate through the rod lengths and update the table with the maximum profit.

  • The final answer will be the maximum profit for the total length of the rod.

Add your answer
right arrow

Q23. Minimum Operation Needed to Convert to the Given String

You are given two strings str1 and str2. Determine the minimum number of operations required to transform str1 into str2.

Explanation:

An operation is def...read more

Ans.

Determine the minimum number of operations needed to transform one string into another by moving characters to the end.

  • Iterate through each character in str1 and check if it matches the first character in str2.

  • If a match is found, calculate the number of operations needed to move the characters to the end.

  • Return the minimum number of operations needed for each test case, or -1 if transformation is not possible.

Add your answer
right arrow

Q24. Binary Tree Diameter Problem Statement

You are given a Binary Tree, and you need to determine the length of the diameter of the tree.

The diameter of a binary tree is the length of the longest path between any ...read more

Ans.

Find the diameter of a binary tree, which is the longest path between any two end nodes.

  • Traverse the tree to find the longest path between two nodes.

  • Use recursion to calculate the diameter of the tree.

  • Keep track of the maximum diameter found during traversal.

  • Example: For input 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the diameter is 6.

Add your answer
right arrow

Q25. Count Pairs with Given Sum

Given an integer array/list arr and an integer 'Sum', determine the total number of unique pairs in the array whose elements sum up to the given 'Sum'.

Input:

The first line contains ...read more
Ans.

Count the total number of unique pairs in an array whose elements sum up to a given value.

  • Use a hashmap to store the frequency of each element in the array.

  • Iterate through the array and for each element, check if (Sum - current element) exists in the hashmap.

  • Increment the count of pairs if the complement exists in the hashmap.

  • Divide the count by 2 to avoid counting duplicates like (arr[i], arr[j]) and (arr[j], arr[i]) separately.

Add your answer
right arrow

Q26. Count Subarrays with Given XOR Problem Statement

You are given an array of integers ARR and an integer X. Your task is to determine the number of subarrays of ARR whose bitwise XOR is equal to X.

Example:

Input...read more
Ans.

Count the number of subarrays in an array whose XOR is equal to a given value.

  • Iterate through the array and keep track of XOR values and their frequencies using a hashmap.

  • For each element, calculate the XOR value with all previous elements and check if the XOR value equals the given X.

  • Use the hashmap to count the number of subarrays with XOR equal to X.

  • Time complexity can be optimized to O(N) using a hashmap to store XOR values and their frequencies.

Add your answer
right arrow

Q27. Bridge in Graph Problem Statement

Given an undirected graph with V vertices and E edges, your task is to find all the bridges in this graph. A bridge is an edge that, when removed, increases the number of conne...read more

Ans.

Find all the bridges in an undirected graph by identifying edges that, when removed, increase the number of connected components.

  • Use Tarjan's algorithm to find bridges in the graph.

  • A bridge is an edge that, when removed, increases the number of connected components.

  • Identify bridges by performing DFS traversal and keeping track of low and discovery times.

  • Return the count of bridges and the vertices defining each bridge in non-decreasing order.

Add your answer
right arrow

Q28. Minimum Insertions to Make a Palindrome

Given a string STR of length N composed of lowercase English letters, your task is to determine the minimum number of characters that need to be added to make the string ...read more

Ans.

Given a string, find the minimum number of characters needed to make it a palindrome.

  • Iterate through the string from both ends and count the number of characters that need to be added to make it a palindrome.

  • Use dynamic programming to optimize the solution by considering subproblems.

  • Handle edge cases such as an already palindrome string or an empty string.

  • Example: For input 'abb', the output should be 1 as adding 'a' makes it 'abba', a palindrome.

Add your answer
right arrow

Q29. Cousins of a Given Node in a Binary Tree

Given a binary tree with 'N' nodes and a specific node in this tree, you need to determine and return a sorted list of the values of the node's cousins. The cousins shou...read more

Ans.

Given a binary tree and a specific node, return a sorted list of the node's cousins.

  • Traverse the binary tree to find the parent of the given node and its depth.

  • Traverse the tree again to find nodes at the same depth but with different parents.

  • Return the sorted list of cousin node values or -1 if no cousins exist.

Add your answer
right arrow

Q30. Delete a Node from a Linked List

You are provided with a linked list of integers. Your task is to implement a function that deletes a node located at a specified position 'POS'.

Input:

The first line contains a...read more
Ans.

Implement a function to delete a node from a linked list at a specified position.

  • Traverse the linked list to find the node at the specified position.

  • Update the pointers of the previous and next nodes to skip the node to be deleted.

  • Handle cases where the position is at the beginning or end of the linked list.

  • Ensure to free the memory of the deleted node to avoid memory leaks.

Add your answer
right arrow

Q31. Rotate Matrix by 90 Degrees Problem Statement

Given a square matrix 'MATRIX' of non-negative integers, rotate the matrix by 90 degrees in an anti-clockwise direction using only constant extra space.

Input:

The ...read more
Ans.

Rotate a square matrix by 90 degrees in an anti-clockwise direction using constant extra space.

  • Iterate through each layer of the matrix from outer to inner layers

  • Swap elements in groups of 4 to rotate the matrix

  • Handle odd-sized matrices separately by adjusting the center element if needed

Add your answer
right arrow

Q32. How to divide the frequency of the clock by three?

Ans.

To divide the frequency of the clock by three, use a counter with a divide-by-three function.

  • Use a counter IC with a divide-by-three function

  • Connect the clock signal to the counter input

  • Use the output of the counter as the new clock signal

View 5 more answers
right arrow

Q33. Reverse Linked List Problem Statement

Given a singly linked list of integers, return the head of the reversed linked list.

Example:

Initial linked list: 1 -> 2 -> 3 -> 4 -> NULL
Reversed linked list: 4 -> 3 -> 2...read more
Ans.

Reverse a singly linked list of integers and return the head of the reversed linked list.

  • Iterate through the linked list and reverse the pointers to point to the previous node.

  • Use three pointers - prev, current, and next to reverse the linked list in O(N) time and O(1) space complexity.

  • Update the head of the reversed linked list as the last node encountered during reversal.

Add your answer
right arrow

Q34. Topological Sort Problem Statement

Given a Directed Acyclic Graph (DAG) consisting of V vertices and E edges, your task is to find any topological sorting of this DAG. You need to return an array of size V repr...read more

Ans.

Topological sort of a Directed Acyclic Graph (DAG) is finding an ordering of vertices where for every directed edge u -> v, u comes before v.

  • Use Depth First Search (DFS) to find the topological ordering of vertices in a DAG.

  • Start by visiting a vertex and recursively visit its neighbors, adding the vertex to the result after visiting all neighbors.

  • Maintain a visited array to keep track of visited vertices and a stack to store the topological ordering.

  • Once all vertices are visi...read more

Add your answer
right arrow

Q35. Longest Increasing Subsequence Problem Statement

Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more

Ans.

Find the length of the longest strictly increasing subsequence in an array of integers.

  • Use dynamic programming to keep track of the longest increasing subsequence ending at each element.

  • Initialize an array to store the length of the longest increasing subsequence ending at each index.

  • Iterate through the array and update the length of the longest increasing subsequence for each element.

  • Return the maximum value in the array as the length of the longest increasing subsequence.

Add your answer
right arrow

Q36. How the operating system taking care of const int i=5; //tell the implementation so that we can't alter the value of i?

Ans.

Operating system uses memory protection to prevent modification of const variables like const int i=5;

  • Operating system marks the memory page containing i as read-only

  • Any attempt to modify i will result in a segmentation fault

  • Compiler may optimize code by replacing i with its value at compile time

Add your answer
right arrow

Q37. Reach the Destination Problem Statement

You are given a source point (sx, sy) and a destination point (dx, dy). Determine if it is possible to reach the destination point using only the following valid moves:

    ...read more
Ans.

The problem involves determining if it is possible to reach a destination point from a source point using specified moves.

  • Iterate through each test case and check if the destination point can be reached from the source point using the given moves.

  • Keep track of the current position and try all possible moves to reach the destination point.

  • Return true if the destination point is reachable, otherwise return false.

Add your answer
right arrow

Q38. Sum of Squares of First N Natural Numbers Problem Statement

You are tasked with finding the sum of squares of the first N natural numbers for given test cases.

Input:

The first line contains an integer 'T', the...read more
Ans.

Calculate the sum of squares of the first N natural numbers for given test cases.

  • Iterate through each test case and calculate the sum of squares using the formula: N*(N+1)*(2N+1)/6

  • Output the result for each test case on a new line

  • Handle constraints efficiently to avoid timeouts

Add your answer
right arrow

Q39. Power of Two Problem Statement

Determine whether a given integer N is a power of two. Return true if it is, otherwise return false.

Explanation

An integer 'N' is considered a power of two if it can be expressed...read more

Ans.

Check if a given integer is a power of two or not.

  • Check if the given integer is greater than 0.

  • Use bitwise operations to determine if the integer is a power of two.

  • Return true if the integer is a power of two, otherwise return false.

Add your answer
right arrow

Q40. Merge K Sorted Arrays Problem Statement

Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.

Input

The f...read more
Ans.

Merge K sorted arrays into a single sorted array.

  • Iterate through all arrays and merge them into a single array.

  • Use a priority queue to efficiently merge the arrays.

  • Ensure the final array is sorted in ascending order.

Add your answer
right arrow

Q41. Spiral Order Traversal of a Binary Tree

Given a binary tree with N nodes, your task is to output the Spiral Order traversal of the binary tree.

Input:

The input consists of a single line containing elements of ...read more
Ans.

Implement a function to return the spiral order traversal of a binary tree.

  • Traverse the binary tree level by level, alternating between left to right and right to left.

  • Use a queue to keep track of nodes at each level.

  • Append nodes to the result list in the order they are visited.

  • Handle null nodes appropriately to maintain the spiral order.

  • Example: For input 1 2 3 -1 -1 4 5, the output should be 1 3 2 4 5.

Add your answer
right arrow

Q42. Stack using Two Queues Problem Statement

Develop a Stack Data Structure to store integer values using two Queues internally.

Your stack implementation should provide these public functions:

Explanation:

1. Cons...read more
Ans.

Implement a stack using two queues to store integer values with specified operations.

  • Create a stack class with two queue data members.

  • Implement push(data) by enqueuing the data into one of the queues.

  • Implement pop() by dequeuing all elements from one queue to another until the last element is reached and return it.

  • Implement top() by dequeuing all elements from one queue to another until the last element is reached, return it, and then enqueue it back.

  • Implement size() by retur...read more

Add your answer
right arrow

Q43. Maximum Subsequence Sum Without Three Consecutive Elements

Given an array A of length N consisting of positive integers, your task is to determine the maximum subsequence sum where no three consecutive elements...read more

Ans.

Find the maximum subsequence sum from an array without selecting three consecutive elements.

  • Use dynamic programming to keep track of the maximum sum without selecting three consecutive elements.

  • At each index, consider the maximum sum with the current element included or excluded.

  • Handle edge cases where the array length is less than 3 separately.

  • Example: For input [1, 2, 3, 4], the maximum sum is 9 (1 + 3 + 4).

Add your answer
right arrow

Q44. Word Search Problem Statement

Given a two-dimensional grid with 'N' rows and 'M' columns consisting of uppercase characters, and a string 'WORD', your task is to determine the number of times the word appears i...read more

Ans.

Count the number of occurrences of a given word in a two-dimensional grid of characters.

  • Iterate through each cell in the grid and check if the word can be formed starting from that cell in any of the eight directions.

  • Use backtracking to explore all possible paths while matching the characters of the word.

  • Keep track of visited cells to avoid revisiting the same cell in the same path.

  • Return the count of occurrences of the word in the grid.

Add your answer
right arrow

Q45. Maximum Number from Linked List Problem Statement

Given a linked list where each node contains a single digit, your task is to construct the largest possible number using these digits.

Objective:

Print the maxi...read more

Ans.

Given a linked list of single digits, construct the largest number possible.

  • Traverse the linked list to extract the digits

  • Sort the digits in descending order

  • Concatenate the sorted digits to form the maximum number

Add your answer
right arrow

Q46. Quick Sort Problem Statement

You are provided with an array of integers. The task is to sort the array in ascending order using the quick sort algorithm.

Quick sort is a divide-and-conquer algorithm. It involve...read more

Ans.

Yes, the quick sort algorithm can be enhanced to achieve NlogN complexity in the worst case by using a randomized version of the algorithm.

  • Randomized quick sort involves randomly selecting the pivot element to reduce the chances of worst-case scenarios.

  • By choosing a random pivot, the algorithm becomes less predictable and more likely to achieve the desired time complexity.

  • This enhancement helps in avoiding the worst-case scenarios where the pivot selection leads to unbalanced...read more

Add your answer
right arrow

Q47. Next Greater Number Problem Statement

Given a string S which represents a number, determine the smallest number strictly greater than the original number composed of the same digits. Each digit's frequency from...read more

Ans.

Given a number represented as a string, find the smallest number greater than the original with the same set of digits.

  • Sort the digits in non-increasing order to find the next greater number.

  • Swap the last two digits to get the smallest greater number.

  • If no greater number exists, return -1.

Add your answer
right arrow

Q48. Trie Data Structure Implementation

Design and implement a Trie (prefix tree) to perform the following operations:

  • insert(word): Add a string "word" to the Trie.
  • search(word): Verify if the string "word" exists...read more
Ans.

Implement a Trie data structure to insert, search, and check for prefixes in strings.

  • Create a TrieNode class with children and isEndOfWord attributes.

  • Implement insert, search, and startsWith methods in the Trie class.

  • Use a Trie to efficiently store and search for strings based on prefixes.

  • Example: insert 'apple', search 'apple' returns true, startsWith 'app' returns true, search 'app' returns false.

Add your answer
right arrow

Q49. Shortest Path in a Binary Maze Problem Statement

Given a maze represented as a binary rectangular matrix of size M*N, where each element can either be 0 or 1, determine the length of the shortest path from a gi...read more

Ans.

Find the length of the shortest path in a binary maze from a given source to destination.

  • Use Breadth First Search (BFS) algorithm to find the shortest path in the binary maze.

  • Create a queue to store the cells to be visited and keep track of visited cells to avoid revisiting them.

  • Check for valid moves in all four directions and update the distance to reach each cell.

  • Return the length of the shortest path if it exists, else return -1.

  • Example: For the given input, the shortest p...read more

Add your answer
right arrow

Q50. Move All Negative Numbers To Beginning

Rearrange a given array 'ARR' with 'N' integers so that all negative numbers appear before all positive numbers.

Follow Up:
Can you solve this in O(1) auxiliary space? 
No...read more
Ans.

Rearrange array with negative numbers at the beginning, order not important.

  • Iterate through the array and swap negative numbers to the beginning using two pointers approach.

  • Maintain one pointer for negative numbers and another for positive numbers.

  • Time complexity: O(N), Space complexity: O(1).

Add your answer
right arrow

Q51. Triplets with Given Sum Problem

Given an array or list ARR consisting of N integers, your task is to identify all distinct triplets within the array that sum up to a specified number K.

Explanation:

A triplet i...read more

Ans.

The task is to find all distinct triplets in an array that sum up to a specified number.

  • Iterate through all possible triplets using three nested loops.

  • Check if the sum of the triplet equals the target sum.

  • Print the triplet if found, else print -1.

Add your answer
right arrow

Q52. Triplets with Given Sum

Given an array ARR consisting of N integers, find all distinct triplets in the array that add up to a given number K.

Example:

Input:
T = 2
N = 5
ARR = [1, 2, 3, 4, 5]
K = 9
N = 4
ARR = [0, ...read more
Ans.

Find all distinct triplets in an array that add up to a given number.

  • Use three nested loops to iterate through all possible triplets.

  • Sort the array first to easily skip duplicates.

  • Use two-pointer technique to find the remaining element for each triplet.

  • Handle edge cases like empty list or no triplet summing up to K.

Add your answer
right arrow

Q53. Cycle Detection in a Singly Linked List

Determine if a given singly linked list of integers forms a cycle or not.

A cycle in a linked list occurs when a node's next points back to a previous node in the list. T...read more

Ans.

Detect if a singly linked list forms a cycle by checking if a node's next pointer points back to a previous node.

  • Use Floyd's Cycle Detection Algorithm to determine if there is a cycle in the linked list.

  • Maintain two pointers, one moving at twice the speed of the other, if they meet at any point, there is a cycle.

  • Check if the next pointer of any node points to a previously visited node to detect a cycle.

Add your answer
right arrow

Q54. Doctor Ninja's House Problem Statement

In a network of 'N' cities with 'M' paths connecting them, Doctor Ninja aims to purchase a house in a city 'X' such that it is possible to reach every other city from city...read more

Ans.

Find the city from which all other cities can be reached in a network of cities connected by paths.

  • Identify the city 'X' from which all other cities can be reached either directly or indirectly.

  • Use depth-first search (DFS) to traverse the graph and find the mother vertex.

  • If multiple options for city 'X' exist, select the city with the smallest number.

  • If no such city exists, return -1.

Add your answer
right arrow

Q55. Implement a Stack Using Two Queues

You are tasked with implementing a Stack data structure specifically designed to store integer data using two Queues. Utilize the inbuilt Queue for this purpose.

Function Requ...read more

Ans.

Implement a Stack data structure using two Queues for integer data.

  • Use two Queues to simulate the Stack behavior.

  • Push elements by enqueueing them in one Queue.

  • Pop elements by dequeueing all elements from the first Queue to the second Queue, except the last one.

  • Top element can be retrieved by dequeuing all elements from the first Queue to the second Queue and then dequeuing the last element.

  • Size can be obtained by returning the size of the first Queue.

  • Check for isEmpty by chec...read more

Add your answer
right arrow

Q56. Reverse the String Problem Statement

You are given a string STR which contains alphabets, numbers, and special characters. Your task is to reverse the string.

Example:

Input:
STR = "abcde"
Output:
"edcba"

Input...read more

Ans.

Reverse a given string containing alphabets, numbers, and special characters.

  • Iterate through the string from the end to the beginning and append each character to a new string.

  • Use built-in functions like reverse() or slicing to reverse the string.

  • Handle special characters and numbers while reversing the string.

  • Ensure to consider the constraints on the input size and number of test cases.

Add your answer
right arrow

Q57. Ceil Value from BST Problem Statement

Given a Binary Search Tree (BST) and an integer, write a function to return the ceil value of a particular key in the BST.

The ceil of an integer is defined as the smallest...read more

Ans.

The problem involves finding the ceil value of a key in a Binary Search Tree (BST).

  • Traverse the BST to find the closest integer greater than or equal to the given key.

  • Compare the key with the current node value and update the ceil value accordingly.

  • Handle cases where the key is equal to a node value or falls between two nodes.

  • Implement a recursive or iterative solution to efficiently find the ceil value.

Add your answer
right arrow

Q58. Build Max Heap Problem Statement

Given an integer array with N elements, the task is to transform this array into a max binary heap structure.

Explanation:

A max-heap is a complete binary tree where each intern...read more

Ans.

The task is to transform an integer array into a max binary heap structure.

  • Create a max heap from the given array by rearranging elements

  • Ensure each internal node has a value greater than or equal to its children

  • Check if the transformed array represents a max-heap and output 1 if true, 0 if false

Add your answer
right arrow

Q59. M - Coloring Problem Statement

Given an undirected graph with 'N' nodes in the form of an adjacency matrix and an integer 'M', determine if it is possible to color the vertices of the graph using at most 'M' co...read more

Ans.

The problem involves determining if a given graph can be colored with at most 'M' colors without adjacent vertices sharing the same color.

  • Create a function that takes the adjacency matrix, number of nodes 'N', and maximum number of colors 'M' as input.

  • Implement a graph coloring algorithm such as backtracking or greedy coloring to check if the graph can be colored with at most 'M' colors.

  • Check if adjacent vertices have the same color while coloring the graph.

  • Return 'Yes' if th...read more

Add your answer
right arrow

Q60. Rotting Oranges Problem Statement

You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:

  • 0 - representing an empty cell
  • 1 - representing a fresh orange...read more
Ans.

Find the minimum time required to rot all fresh oranges in a grid.

  • Use Breadth First Search (BFS) to simulate the rotting process of oranges.

  • Keep track of the time taken to rot all oranges and the count of fresh oranges remaining.

  • If all fresh oranges are not rotten after simulation, return -1.

  • Handle edge cases like empty grid or no fresh oranges present.

  • Example: For the given grid, the minimum time required is 4 seconds.

Add your answer
right arrow

Q61. Detect and Remove Loop in Linked List

For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.

Expected Complexity:

Aim for a...read more

Ans.

Detect and remove loop in a singly linked list in place with O(n) time complexity and O(1) space complexity.

  • Use Floyd's Cycle Detection Algorithm to identify the loop in the linked list.

  • Once the loop is detected, use two pointers approach to find the start of the loop.

  • Adjust the pointers to remove the loop and return the modified linked list.

  • Example: For input 5 2 and 1 2 3 4 5, return 1 2 3 4 5 without the loop.

Add your answer
right arrow

Q62. Most Stones Removed with Same Row or Column

On a 2-D plane, there are ‘N’ stones placed at some integer coordinate points. Each coordinate point can have at most one stone. A stone can be removed if it shares t...read more

Ans.

Given a 2-D plane with stones at integer coordinate points, find the maximum number of stones that can be removed by sharing the same row or column.

  • Iterate through the stones and create a graph where stones in the same row or column are connected.

  • Use depth-first search (DFS) to find connected components in the graph.

  • The maximum number of stones that can be removed is the total number of stones minus the number of connected components.

Add your answer
right arrow

Q63. All Possible Balanced Parentheses Problem Statement

Given a positive integer N, generate all possible sequences of balanced parentheses using N pairs of parentheses.

A sequence of brackets is called balanced if...read more

Ans.

Generate all possible sequences of balanced parentheses using N pairs of parentheses.

  • Use backtracking to generate all possible combinations of balanced parentheses.

  • Keep track of the number of opening and closing parentheses used.

  • Add opening parentheses if there are remaining, and add closing parentheses only if there are more opening parentheses than closing.

  • Recursively generate all valid combinations.

  • Return the list of valid combinations for each test case.

Add your answer
right arrow

Q64. Substrings Differ by One Problem Statement

Ninja needs help in a battle against the string man. Given two strings, 'S' and 'T', the task is to find the number of substrings in 'S' that differ from some substrin...read more

Ans.

The task is to find the number of substrings in 'S' that differ from some substrings of 'T' by exactly one character.

  • Iterate through all substrings of 'S' and 'T' and compare them character by character to find the ones that differ by exactly one character.

  • Use nested loops to generate all possible substrings of 'S' and 'T'.

  • Count the number of substrings that differ by exactly one character and return the total count.

Add your answer
right arrow

Q65. Cycle Detection in Undirected Graph Problem Statement

You are provided with an undirected graph containing 'N' vertices and 'M' edges. The vertices are numbered from 1 to 'N'. Your objective is to determine whe...read more

Ans.

Detect cycles in an undirected graph.

  • Use Depth First Search (DFS) to detect cycles in the graph.

  • Maintain a visited array to keep track of visited vertices.

  • If a visited vertex is encountered again during DFS, a cycle exists.

  • Check for cycles in each connected component of the graph.

  • Example: For input N=3, Edges=[[1, 2], [2, 3], [1, 3]], output is Yes.

Add your answer
right arrow

Q66. Circle of Words Problem Statement

Given an array or list of words, determine whether the words can be rearranged to form a circle where the last character of one word matches the first character of the next.

In...read more

Ans.

Check if given words can be rearranged to form a circle where the last character of one word matches the first character of the next.

  • Create a graph where each word is a node and there is an edge between two nodes if the last character of one word matches the first character of the next.

  • Check if the graph is strongly connected, meaning there is a path between every pair of nodes.

  • If the graph is strongly connected, return true; otherwise, return false.

Add your answer
right arrow

Q67. Sum of Digits Problem Statement

Given an integer 'N', continue summing its digits until the result is a single-digit number. Your task is to determine the final value of 'N' after applying this operation iterat...read more

Ans.

Given an integer 'N', find the final single-digit value by summing its digits iteratively.

  • Iteratively sum the digits of the given integer until the result is a single-digit number

  • Output the final single-digit integer for each test case

  • Handle multiple test cases efficiently

Add your answer
right arrow

Q68. Binary Tree to Doubly Linked List

Transform a given Binary Tree into a Doubly Linked List.

Ensure that the nodes in the Doubly Linked List follow the Inorder Traversal of the Binary Tree.

Input:

The first line ...read more
Ans.

Convert a Binary Tree into a Doubly Linked List following Inorder Traversal.

  • Perform Inorder Traversal of the Binary Tree to get the nodes in order.

  • Create a Doubly Linked List by linking the nodes in the order obtained from Inorder Traversal.

  • Return the head of the Doubly Linked List as the output.

Add your answer
right arrow

Q69. Maximum Product Subarray Problem Statement

Given an array of integers, determine the contiguous subarray that produces the maximum product of its elements.

Explanation:

A subarray can be derived from the origin...read more

Ans.

Find the maximum product of a contiguous subarray in an array of integers.

  • Iterate through the array and keep track of the maximum and minimum product ending at each index.

  • Update the maximum product by considering the current element, the maximum product ending at the previous index multiplied by the current element, and the minimum product ending at the previous index multiplied by the current element.

  • Update the minimum product similarly.

  • Return the maximum product found durin...read more

Add your answer
right arrow

Q70. Maximum Sum Rectangle Problem

Given an M x N matrix of integers ARR, your task is to identify the rectangle within the matrix that has the greatest sum of its elements.

Input:

The first line of input contains a...read more
Ans.

The task is to find the rectangle within a matrix that has the greatest sum of its elements.

  • Iterate through all possible rectangles within the matrix

  • Calculate the sum of each rectangle and keep track of the maximum sum

  • Return the maximum sum obtained from any rectangle within the matrix

Add your answer
right arrow

Q71. Convert Binary Tree to Mirror Tree

Convert a given binary tree into its mirror tree, where the left and right children of all non-leaf nodes are interchanged.

Input:

An integer ‘T’ denoting the number of test c...read more
Ans.

Convert a binary tree into its mirror tree by interchanging left and right children of non-leaf nodes.

  • Traverse the tree in postorder fashion and swap the left and right children of each node.

  • Recursively call the function on the left and right subtrees.

  • Modify the tree in place without creating a new tree.

Add your answer
right arrow

Q72. What is FSM and explain the differences between the Mealy and Moore machines?

Ans.

FSM stands for Finite State Machine. Mealy and Moore machines are two types of FSMs with differences in output.

  • FSM is a mathematical model used to describe the behavior of a system with a finite number of states.

  • Mealy machines produce outputs based on both the current state and the inputs.

  • Moore machines produce outputs based only on the current state.

  • Mealy machines have more flexibility in generating outputs, while Moore machines are simpler to design and analyze.

  • Example: In ...read more

View 1 answer
right arrow

Q73. List some scenarios where you observe issues with the heap dump and provide recommendations to the dev team. Follow-up questions will be asked based on your answer to the previous questions.

Ans.

Scenarios where issues with heap dump occur and recommendations for dev team

  • Heap dump size is too large

  • Heap dump is not generated at the right time

  • Heap dump is not analyzed properly

  • Heap dump is not shared with the right team members

  • Recommendations: Optimize code to reduce memory usage, generate heap dump at appropriate times, analyze heap dump thoroughly, share heap dump with relevant team members

Add your answer
right arrow

Q74. Check if Two Trees are Mirror

Given two arbitrary binary trees consisting of 'N' and 'M' number of nodes respectively, your task is to check whether the two trees are mirror images of each other or not.

Definit...read more

Ans.

Check if two binary trees are mirror images of each other.

  • Compare the left subtree of the first tree with the right subtree of the second tree.

  • Compare the right subtree of the first tree with the left subtree of the second tree.

  • Check if the roots of both trees are the same.

Add your answer
right arrow

Q75. Implement a Stack using Queues

Create a Stack data structure designed specifically to store integer data using two queues.

Explanation:

You need to implement a stack using two internal queues. You can utilize a...read more

Ans.

Implement a Stack using Queues to store integer data with push, pop, top, size, and isEmpty functions.

  • Use two queues to simulate a stack, with one queue acting as the main stack and the other for temporary storage.

  • For push operation, enqueue the new element to the temporary queue, then dequeue all elements from the main queue to the temporary queue, and finally swap the queues.

  • For pop operation, dequeue the top element from the main queue.

  • For top operation, return the front e...read more

Add your answer
right arrow

Q76. Find Shortest Path in a Tree

Given a tree with 'N' nodes and 'N - 1' distinct edges, along with two nodes 'N1' and 'N2', find and print the shortest path between 'N1' and 'N2'.

Explanation:

A tree is a nonlinea...read more

Ans.

Find the shortest path between two nodes in a tree.

  • Use Breadth First Search (BFS) algorithm to find the shortest path in a tree.

  • Start BFS from one of the nodes and keep track of the parent of each node to reconstruct the path.

  • Once both nodes are reached, backtrack from both nodes to the root to find the common ancestor and then reconstruct the path.

  • Consider implementing a function to find the LCA (Lowest Common Ancestor) of two nodes in a tree.

  • Handle cases where one node is a...read more

Add your answer
right arrow

Q77. Minimum Insertions to Make a String Palindrome

Determine the minimal number of characters needed to insert into a given string STR to transform it into a palindrome.

Example:

Input:
STR = "abcaa"
Output:
2
Expl...read more
Ans.

The task is to find the minimum number of characters needed to insert into a given string to make it a palindrome.

  • Use dynamic programming to find the longest palindromic subsequence of the given string.

  • Subtract the length of the longest palindromic subsequence from the length of the original string to get the minimum insertions required.

  • Handle edge cases like an empty string or a string that is already a palindrome.

  • Example: For input 'abcaa', the longest palindromic subsequen...read more

Add your answer
right arrow

Q78. Merge Sort Linked List Problem Statement

You are given a singly linked list of integers. Your task is to sort the linked list using the merge sort algorithm.

Explanation:

Merge Sort is a divide and conquer algo...read more

Ans.

Implement merge sort algorithm to sort a singly linked list of integers.

  • Divide the linked list into two halves using slow and fast pointer technique.

  • Recursively sort the two halves.

  • Merge the sorted halves using a merge function.

  • Handle base cases like empty list or single node list.

  • Ensure the termination of the linked list with -1 at the end.

Add your answer
right arrow

Q79. Longest Palindromic Substring Problem Statement

You are provided with a string STR of length N. The goal is to identify the longest palindromic substring within this string. In cases where multiple palindromic ...read more

Ans.

Given a string, find the longest palindromic substring, prioritizing the one with the smallest start index.

  • Iterate through the string and expand around each character to find palindromes

  • Keep track of the longest palindrome found, updating it as needed

  • Return the longest palindromic substring with the smallest start index

Add your answer
right arrow

Q80. Maximum Sum Path in a Binary Tree

Your task is to determine the maximum possible sum of a simple path between any two nodes (possibly the same) in a given binary tree of 'N' nodes with integer values.

Explanati...read more

Ans.

Find the maximum sum of a simple path between any two nodes in a binary tree.

  • Use a recursive approach to traverse the binary tree and calculate the maximum sum path.

  • Keep track of the maximum sum path found so far while traversing the tree.

  • Consider all possible paths between any two nodes in the tree to find the maximum sum.

Add your answer
right arrow

Q81. Rat in a Maze Problem Statement

You need to determine all possible paths for a rat starting at position (0, 0) in a square maze to reach its destination at (N-1, N-1). The maze is represented as an N*N matrix w...read more

Ans.

Find all possible paths for a rat in a maze from source to destination.

  • Use backtracking to explore all possible paths in the maze.

  • Keep track of visited cells to avoid revisiting them.

  • Recursively move in all directions (up, down, left, right) until reaching the destination.

  • Return the list of valid paths sorted in alphabetical order.

Add your answer
right arrow

Q82. Draw the CMOS inverter circuit and derive the transfer characteristics of inverter.What are the regions of operations of it?

Ans.

Answering a question about CMOS inverter circuit and its transfer characteristics.

  • The CMOS inverter circuit consists of a PMOS and an NMOS transistor connected in series.

  • The transfer characteristics of the inverter can be derived by plotting the output voltage against the input voltage.

  • The regions of operation of the inverter are the cutoff region, the linear region, and the saturation region.

  • In the cutoff region, both transistors are off and the output voltage is high.

  • In the...read more

Add your answer
right arrow

Q83. What do you think is an area of improvement for you?

Ans.

I need to improve my time management skills.

  • Prioritize tasks based on urgency and importance

  • Set realistic deadlines and stick to them

  • Avoid multitasking and focus on one task at a time

  • Use tools like calendars and to-do lists to stay organized

Add your answer
right arrow

Q84. How do you gather NFR from the client if an application is totally new and the client is not aware of the performance testing?

Ans.

To gather NFR from an unaware client for a new application, follow these steps:

  • Explain the importance of performance testing and its benefits

  • Provide examples of how performance issues can impact the application and business

  • Ask the client about their expectations for the application's performance

  • Discuss the application's usage scenarios and expected user load

  • Collaborate with the development team to identify potential performance bottlenecks

  • Use industry standards and best pract...read more

View 1 answer
right arrow

Q85. Rain Water Trapping Problem Statement

Given an array/list ARR of size N, representing an elevation map where each element ARR[i] denotes the elevation of the i-th bar. Your task is to calculate and print the to...read more

Ans.

Calculate the total amount of rainwater that can be trapped between given elevations in an array.

  • Use two-pointer approach to keep track of left and right boundaries.

  • Calculate the trapped water by finding the minimum of maximum heights on left and right sides for each bar.

  • Sum up the trapped water for all bars to get the total amount of rainwater trapped.

Add your answer
right arrow

Q86. Implementing a Priority Queue Using Heap

Ninja has been tasked with implementing a priority queue using a heap data structure. However, he is currently busy preparing for a tournament and has requested your ass...read more

Ans.

Implement a priority queue using a heap data structure with push, pop, getMaxElement, and isEmpty functions.

  • Implement push function to insert element into the queue

  • Implement pop function to remove the largest element from the queue

  • Implement getMaxElement function to return the largest element

  • Implement isEmpty function to check if the queue is empty

Add your answer
right arrow

Q87. AVL Tree Insertion Task

Create an AVL tree from scratch. You will be provided with ‘N’ values representing node values you need to insert into the AVL tree. After inserting all values, return the root of the AV...read more

Ans.

Implement a function to create an AVL tree from scratch by inserting given values and return the root of the tree.

  • Create a Node class with data, left, and right pointers for the AVL tree nodes.

  • Implement rotation functions (left rotation, right rotation) to maintain AVL tree balance.

  • Update the height and balance factor of nodes after each insertion to ensure AVL tree properties are maintained.

Add your answer
right arrow

Q88. By how many method we can allocate the memory in C and what is the difference between malloc and calloc. And which is faster and why?

Ans.

Two methods to allocate memory in C are malloc and calloc. Malloc allocates memory block of given size while calloc initializes the allocated memory block to zero.

  • Malloc allocates memory block of given size while calloc initializes the allocated memory block to zero.

  • Malloc returns a pointer to the first byte of allocated memory block while calloc returns a pointer to the first byte of initialized memory block.

  • Malloc is faster than calloc as it does not initialize the memory b...read more

Add your answer
right arrow

Q89. How many types of CPU scheduling are there and explain all. Which one is better and why and tell the feasibilty also?

Ans.

There are 6 types of CPU scheduling: FCFS, SJF, SRTF, Priority, Round Robin, and Multilevel Queue. Each has its own advantages and disadvantages.

  • FCFS (First-Come-First-Serve) - processes are executed in the order they arrive

  • SJF (Shortest-Job-First) - shortest job is executed first

  • SRTF (Shortest-Remaining-Time-First) - preemptive version of SJF

  • Priority - processes with higher priority are executed first

  • Round Robin - each process is given a time slice to execute, then moved to ...read more

Add your answer
right arrow

Q90. Palindrome Linked List Problem Statement

You are provided with a singly linked list of integers. Your task is to determine whether the given singly linked list is a palindrome. Return true if it is a palindrome...read more

Ans.

Check if a given singly linked list is a palindrome or not.

  • Use two pointers approach to find the middle of the linked list

  • Reverse the second half of the linked list

  • Compare the first half with the reversed second half to determine if it's a palindrome

Add your answer
right arrow

Q91. Count Diagonal Paths

You are given a binary tree. Your task is to return the count of the diagonal paths to the leaf of the given binary tree such that all the values of the nodes on the diagonal are equal.

Inp...read more

Ans.

Count the number of diagonal paths in a binary tree where all nodes on the diagonal have equal values.

  • Traverse the binary tree in a diagonal manner and keep track of nodes with equal values.

  • Use recursion to explore all possible diagonal paths in the tree.

  • Count the number of paths where all nodes on the diagonal have the same value.

Add your answer
right arrow

Q92. Minimum Jumps Problem Statement

Bob and his wife are in the famous 'Arcade' mall in the city of Berland. This mall has a unique way of moving between shops using trampolines. Each shop is laid out in a straight...read more

Ans.

Find the minimum number of trampoline jumps Bob needs to make to reach the final shop, or return -1 if it's impossible.

  • Use Breadth First Search (BFS) to find the minimum number of jumps needed.

  • Keep track of the visited shops to avoid revisiting them.

  • If a shop has an Arr value of 0, it is impossible to reach the last shop.

  • Return -1 if the last shop cannot be reached.

Add your answer
right arrow

Q93. Remove BST Keys Outside Given Range

Given a Binary Search Tree (BST) and a specified range [min, max], your task is to remove all keys from the BST that fall outside this range. The BST should remain valid afte...read more

Ans.

Remove BST keys outside given range while maintaining validity of BST.

  • Traverse the BST in inorder fashion and remove nodes outside the specified range.

  • Recursively call the function on left and right subtrees.

  • Adjust the pointers of parent nodes accordingly after removing nodes.

  • Ensure the BST remains valid after modifications.

  • Return the inorder traversal of the adjusted BST.

Add your answer
right arrow

Q94. Water Supply Optimization Problem

Given N houses in a village, determine the minimum cost to supply water to all houses either by building wells in the houses or by connecting them with pipes.

Explanation:

For ...read more

Ans.

Determine the minimum cost to supply water to all houses in a village by building wells or connecting them with pipes.

  • Iterate through all possible connections and choose the minimum cost between building a well or connecting two houses with a pipe.

  • Use a minimum spanning tree algorithm like Kruskal's or Prim's to find the optimal cost.

  • Consider the cost of building wells and connecting pipes to minimize the total cost.

  • Example: For the input (3 2, 1 2 2, 1 2 1, 2 3 1), the optim...read more

Add your answer
right arrow

Q95. BST to Greater Tree Conversion

Convert a given binary search tree (BST) with 'N' nodes into a Greater Tree. In this transformation, each node's data is modified to the sum of the original node's data plus the s...read more

Ans.

Convert a given BST into a Greater Tree by updating each node's data to the sum of original data and all greater nodes' data.

  • Traverse the BST in reverse inorder (right, root, left) to update each node's data with the sum of all greater nodes' data.

  • Keep track of the running sum of nodes visited so far to update the current node's data.

  • Modify the BST in place without using any extra data structures.

  • Example: Input BST: 4 1 6 0 2 5 7 -1 -1 -1 3 -1 -1 -1 -1. Output Greater Tree: 2...read more

Add your answer
right arrow

Q96. For statement const int *p = 5, which is true from given below two statement: a) int a; p = &a; b) *p = 0

Ans.

Cannot modify value pointed by p, but can change the address it points to.

  • p is a pointer to a constant integer with value 5

  • a) is valid as p can point to a non-constant integer

  • b) is invalid as *p is a constant and cannot be modified

Add your answer
right arrow

Q97. What is CMOS?Why CMOS?Distinguish the advantages and disadvantages of it?compare it with BJT

Ans.

CMOS is a type of semiconductor technology used in digital circuits.

  • CMOS stands for Complementary Metal-Oxide-Semiconductor.

  • It uses both p-type and n-type MOSFETs to achieve low power consumption and high noise immunity.

  • Advantages include low power consumption, high noise immunity, and compatibility with digital circuits.

  • Disadvantages include higher cost and lower speed compared to other technologies.

  • BJT (Bipolar Junction Transistor) is an alternative technology that is faste...read more

Add your answer
right arrow

Q98. How to Work with dynamic data, how to remove duplicate data or fix the data

Ans.

To work with dynamic data, remove duplicates and fix errors, use data cleaning techniques.

  • Use software tools like OpenRefine or Excel to clean data

  • Identify and remove duplicate data using unique identifiers

  • Fix errors by standardizing data formats and using regular expressions

  • Use data validation to ensure accuracy and completeness

  • Create a data cleaning plan and document all changes made

  • Test the cleaned data to ensure it meets the desired quality standards

View 1 answer
right arrow

Q99. Merge Sort Problem Statement

You are given a sequence of numbers, ARR. Your task is to return a sorted sequence of ARR in non-descending order using the Merge Sort algorithm.

Explanation:

The Merge Sort algorit...read more

Ans.

Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.

  • Divide the input array into two halves recursively until each array has only one element.

  • Merge the sorted halves to produce a completely sorted array.

  • Time complexity of Merge Sort is O(n log n).

  • Example: Input: [3, 1, 4, 1, 5], Output: [1, 1, 3, 4, 5]

Add your answer
right arrow

Q100. Longest Substring Without Repeating Characters Problem Statement

Given a string S of length L, determine the length of the longest substring that contains no repeating characters.

Example:

Input:
"abacb"
Output...read more
Ans.

Find the length of the longest substring without repeating characters in a given string.

  • Use a sliding window approach to keep track of the longest substring without repeating characters.

  • Use a hashmap to store the index of each character in the string.

  • Update the start index of the window when a repeating character is encountered.

  • Calculate the maximum length of the window as you iterate through the string.

  • Return the maximum length as the result.

Add your answer
right arrow
1
2
3
4
Next

More about working at Samsung

Back
Awards Leaf
AmbitionBox Logo
Top Rated Mega Company - 2024
Awards Leaf
Awards Leaf
AmbitionBox Logo
Top Rated Consumer Electronics Company - 2024
Awards Leaf
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos

Interview Process at Samsung

based on 397 interviews
Interview experience
4.2
Good
View more
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Interview Questions from Similar Companies

HCLTech Logo
3.5
 • 2.1k Interview Questions
Axis Bank Logo
3.8
 • 488 Interview Questions
Dr. Reddy's Logo
4.0
 • 258 Interview Questions
Escorts Kubota Limited Logo
4.1
 • 169 Interview Questions
Intas Pharmaceuticals Logo
4.1
 • 162 Interview Questions
Myntra Logo
4.0
 • 158 Interview Questions
View all
Recently Viewed
AWARDS
ABECA 2024
AmbitionBox Employee Choice Awards
REVIEWS
FMC Corporation
No Reviews
REVIEWS
FMC Corporation
No Reviews
REVIEWS
Sanofi
No Reviews
REVIEWS
Sanofi
No Reviews
REVIEWS
GlaxoSmithKline Pharmaceuticals
No Reviews
JOBS
Samsung
No Jobs
REVIEWS
Samsung
No Reviews
REVIEWS
Godrej & Boyce Manufacturing
No Reviews
JOBS
Sanofi
No Jobs
Top Samsung Interview Questions And Answers
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

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