Samsung
400+ Interview Questions and Answers
You will be given a starting point (sx, sy) and a destination point (dx, dy) in the two-dimensional coordinate system representing the universe.
Your spacecraft can move only in ...read more
For a given string(str), remove all the consecutive duplicate characters.
Example:
Input String: "aaaa" Expected Output: "a" Input String: "aabbbcc" Expected Output: "abc"
Input F...read more
You are given an array 'nums' consisting of first N positive integers. But from the N integers, one of the integers occurs twice in the array, and one of the integers is mis...read more
You are given an array 'ARR' of N integers. Each integer represents the height of a balloon. So, there are N balloons lined up.
Your aim is to destroy all these balloons. Now, a balloon can onl...read more
Given a binary tree, print the top view of it. The output nodes can be printed in any order. Expected time complexity is O(n)
1
/ \
2 3
/ \ / \
4 5 6 7
Top view of the above binar...read more
Find maximum possible stolen value from houses
There are n houses build in a line, each of which contains some value in it. A thief is going to steal the maximal value of these houses, but he can’t ste...read more
You have been given a Binary Tree of distinct integers and two nodes ‘X’ and ‘Y’. You are supposed to return the LCA (Lowest Common Ancestor) of ‘X’ and ‘Y’.
The LCA of ‘X’ and ‘Y’ in the bina...read more
To find the merging point of link list(Given pointers to the head nodes of 2 linked lists that merge together at some point, find the Node where the two lists merge. It is guarant...read more
You are given a Singly Linked List of integers and a positive integer 'K'. Modify the linked list by reversing every alternate 'K' nodes of the linked list.
A singly linked list is a ty...read more
For a given array with N elements, you need to find the length of the longest subsequence from the array such that all the elements of the subsequence are sorted in strictly increa...read more
You have been given a long type array/list 'ARR' of size 'N'. It represents an elevation map wherein 'ARR[i]' denotes the elevation of the 'ith' bar. Print the total amount of rainwater that ...read more
A thief is robbing a store and can carry a maximum weight of ‘W’ into his knapsack. There are 'N' items available in the store and the weight and value of each item is known to the thief. Consider...read more
You are given an array 'ARR' consisting of 'N' integers. You need to rearrange the array elements such that all negative numbers appear before all positive numbers.
Follow ...read more
You are given N stones, labeled from 1 to N. The i-th stone has the weight W[i]. There are M colors, labeled by integers from 1 to M. The i-th stone has the color C[i] (of course, an integer b...read more
You are given a Binary tree. You have to count and return the number of leaf nodes present in it.
A binary tree is a tree data structure in which each node has at most two children, which are re...read more
You have been given a gold mine represented by a 2-d matrix of size ('N' * 'M') 'N' rows and 'M' columns. Each field/cell in this mine contains a positive integer,...read more
You have been given a binary matrix of size 'N' * 'M' where each element is either 0 or 1. You are also given a source and a destination cell, both of them lie within the matrix....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 lis...read more
You have been given an integer 'N'. Your task is to return true if it is a power of two. Otherwise, return false.
An integer 'N' is a power of two, if it can be expressed as 2 ^ 'K' where 'K' is an ...read more
You have been given ‘K’ different arrays/lists, which are sorted individually (in ascending order). You need to merge all the given arrays/list such that the output array/list should be sor...read more
You have been given a gold mine represented by a 2-d matrix of size ('N' * 'M') 'N' rows and 'M' columns. Each field/cell in this mine contains a positive integer, the amount of gold in kgs.
In...read more
You are given a binary tree of 'N' nodes.
Your task is to find the path from the leaf node to the root node which has the maximum path sum among all the root to leaf paths....read more
Given a rod of length ‘N’ units. The rod can be cut into different sizes and each size has a cost associated with it. Determine the maximum cost obtained by cutting the rod and selling its p...read more
You are given an array of integers. You need to sort the array in ascending order using quick sort.
Quick sort is a divide and conquer algorithm in which we choose a pivot point and partition the arra...read more
You have been given an integer array/list(arr) and a number 'Sum'. Find and return the total number of pairs in the array/list which when added, results equal to the 'Sum'.
Note:
G...read more
You are given a string 'STR' of length 'N' consisting of lowercase English Alphabet letters. Your task is to return the count of minimum characters to be added to make the string a palindrome....read more
Given an array of integers, and a number ‘sum’, find number of pairs in the array whose sum is equal to given sum.
Examples :
Input : arr[] = {1, 5, 7, -1, 5},
sum = 6
Output : 3 [ ...read more
Implement a Stack Data Structure specifically to store integer data using two Queues.
There should be two data members, both being Queues to store the data internally. You may use the...read more
You are given an integer 'N'. You need to find the sum of squares of the first 'N' natural numbers.
For example:
If 'N' = 4. You need to return 1^2 + 2^2 + 3^2 + 4^2 = 3...read more
You are given an array/list ARR consisting of N integers. Your task is to find all the distinct triplets present in the array which adds up to a given number K.
An array is said to have a...read more
You have been given a binary tree of 'N' nodes. Print the Spiral Order traversal of this binary tree.
For example
For the given binary tree [1, 2, 3, -1, -1, 4, 5, -1, -1,...read more
You are given two sorted linked lists. You have to merge them to produce a combined sorted linked list. You need to return the head of the final linked list.
Note:
The given linked ...read more
Given a string 'S' of length 'L', return the length of the longest substring without repeating characters.
Example:
Suppose given input is "abacb", then the length ...read more
You are given a string ('STR') of length 'N'. Find the longest palindromic substring. If there is more than one palindromic substring with the maximum length, return the one with th...read more
You are given a Binary Tree. You are supposed to return the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any two end nodes i...read more
You have been given a linked list of integers. Your task is to write a function that deletes a node from a given position, 'POS'.
Note :
Assume that the Indexing for the linked lis...read more
You are given a square matrix of non-negative integers 'MATRIX'. Your task is to rotate that array by 90 degrees in an anti-clockwise direction using constant extra space.
For example...read more
Given a binary tree of N nodes and a node of this tree, you need to return a list containing the values of the cousins of the given node in the given binary tree sorted by no...read more
Given a binary tree, convert this binary tree into its mirror tree.
A binary tree is a tree in which each parent node has at most two children.
Mirror of a Tree: Mirror of a Bi...read more
Given a singly linked list, you have to detect the loop and remove the loop from the linked list, if present. You have to make changes in the given linked list itself and return the update...read more
You have been given an undirected graph with 'N' vertices and 'M' edges. The vertices are labelled from 1 to 'N'.
Your task is to find if the graph contains a cycle or not.
A ...read more
You have been given a long type array/list 'ARR' of size 'N'. It represents an elevation map wherein 'ARR[i]' denotes the elevation of the 'ith' bar. Print the total amount of rainwat...read more
Q43. 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?
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
Given the count of total stones in a game. Two-player ‘Ale’ and ‘Bob’ are playing the game. Your task is to find who will win the game if both the players are playing optimally.
Rules of the game....read more
Q45. How to divide the frequency of the clock by two?
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.
You have given a Singly Linked List of integers, determine if it forms a cycle or not.
A cycle occurs when a node's next points back to a previous node in the list. The li...read more
Given a maze in the form of a binary rectangular matrix of size M*N, where each element can either be 0 or 1, the task is to find the length of the shortest path in a maze from a g...read more
A palindrome string is one that reads the same backward as well as forward. Given a string 'STR', you need to tell the minimum number of characters needed to insert...read more
You are given two strings 'str1' and 'str2'. Find the minimum operations required to convert str1 into str2.
An Operation is defined as:
A character from a...read more
Given an array of integers ‘ARR’ and an integer ‘X’, you are supposed to find the number of subarrays of 'ARR' which have bitwise XOR of the elements equal to 'X'.
Note:
An array ‘...read more
Q51. Design a sequential circuit to detect a sequence 001001?Explain it?How can you reduce the minimum number of states in this design?
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
Questions related to dependency injection, which you should use while writing test class @Autowired or create a new instance using new keyword. Also i remember the puzzle which was asked to me, it was the...read more
Given an undirected graph of V vertices and E edges. Your task is to find all the bridges in the given undirected graph. A bridge in any graph is defined as an edge which, when removed, makes ...read more
Implement a Stack Data Structure specifically to store integer data using two Queues.
There should be two data members, both being Queues to store the data internally. You may use the inbuilt Q...read more
You are given a two-dimensional grid having 'N' rows and 'M' columns, consisting of upper case characters. You are also given a word 'WORD'. You have to find the number of occurrences of that word i...read more
You have been given a grid containing some oranges. Each cell of this grid has one of the three integers values:
This time Ninja is fighting with string man, but string man is too powerful for the Ninja to defeat him alone. So Ninja needs your help to defeat him, Ninja has two strings ‘S’ and ‘T’ t...read more
Given a binary tree of integers, you are supposed to modify the given binary tree to a sum tree where each node value is replaced by the sum of the values of both left and r...read more
Implement a Stack Data Structure specifically to store integer data using two Queues.
There should be two data members, both being Queues to store the data internally. You may use th...read more
You have been given a Binary Tree of 'N' nodes where the nodes have integer values.
Your task is to find the largest number that could be formed by concatenating all its nodes value...read more
You are given an array “arr'' of integers. Your task is to find the contiguous subarray within the array which has the largest product of its elements. You have to report this maximum pr...read more
There is a source (S) and destination (D) and a spacecraft has to go from S to D. There are N number of wormholes in between which has the following properties:
Each wormhole has ...read more
Ninja is learning data structures and came across a doubly linked list. Now he wants to remove a particular element from the linked list. Can you help Ninja do so and return the final linked ...read more
A Directed Acyclic Graph (DAG) is a directed graph that contains no cycles.
Topological Sorting of DAG is a linear ordering of vertices such that for every directed edge from vertex ‘u’ to verte...read more
Given a source point (sx, sy) and a destination point (dx, dy), the task is to check if it is possible to reach the destination point using the following valid moves:
(a, b) -> (a + b, b) (...read more
You are given a tree with 'N' nodes with 'N' - 1 distinct edge. You are also given two nodes 'N1' and 'N2'. You have to find and print the shortest path between 'N1' and 'N2'.
A tree data structure is ...read more
You are given a string 'STR'. The string contains [a-z] [A-Z] [0-9] [special characters]. You have to find the reverse of the string.
For example:
If the given string is: STR = "abcde". You h...read more
Ninja is given an integer ‘N’. One day Ninja decides to do the sum of all digits and replace the ‘N’ with the sum of digits until it becomes less than 10. Ninja wants to find what will be the value...read more
You are given a string (STR) of length N.
Your task is to find the longest palindromic substring. If there is more than one palindromic substring with the maximum length, return the...read more
You are given an array A of length N consisting of positive integers. Your task is to print the maximum subsequence sum such that no three consecutive e...read more
Given a sequence of numbers ‘ARR’. Your task is to return a sorted sequence of ‘ARR’ in non-descending order with help of the merge sort algorithm.
Example :
Merge Sort Algorithm - Merge sort is a Div...read more
Given a linked list such that each node represents a digit. Construct the maximum number possible from the given digits.
You just need to print the maximum Integer that can be formed
Input fo...read more
Given a Binary Tree, convert this binary tree to a Doubly Linked List.
A Binary Tree (BT) is a data structure in which each node has at most two children.
A Doub...read more
You are given a singly Linked List of integers. Your task is to return true if the given singly linked list is a palindrome otherwise returns false.
For example:
The given linked list is 1...read more
Q75. How to divide the frequency of the clock by three?
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
Implement Trie Data Structure to support these operations:
insert(word) - To insert a string "word" in Trie search(word) - To check if string "word" is present in Trie or not. startsWith(word) - T...read more
Bob lives with his wife in a city named Berland. Bob is a good husband, so he goes out with his wife every Friday to ‘Arcade’ mall.
‘Arcade’ is a very famous mall in Berland. It has a very unique t...read more
Q78. How the operating system taking care of const int i=5; //tell the implementation so that we can't alter the value of i?
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
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increa...read more
There are ‘N’ cities and ‘M’ paths connecting them. Doctor Ninja wants to purchase a house in a city ‘X’ such that she can reach any city from the city ‘X’.
Your task is to help Ninja to fin...read more
You are given an array/list of words, your task is to check whether the individual words can be rearranged to form a circle.
Two words, ‘X’ and ‘Y’, can be put together in a circle if the last ch...read more
You are given a string S which represents a number. You have to find the smallest number strictly greater than the given number which contains the same set of digits as of the original number...read more
You are given an undirected graph with N nodes in the form of an adjacency matrix. You are also given an integer M.
Your task is to find if you can color the vertices of the graph using at m...read more
On a 2-D plane, we place ‘N’ ‘stones’ at some integer coordinate points. Each coordinate point may have at most one stone.
A stone can be removed if it shares either t...read more
You are given an M X N matrix of integers ARR. Your task is to find the maximum sum rectangle.
Maximum sum rectangle is a rectangle with the maximum value for the sum of integers present wi...read more
You are given a Singly Linked List of integers. You need to reverse the Linked List by changing the links between nodes.
Input Format :
The first line of input contains a single integer T, re...read more
You are given a starting position for a rat which is stuck in a maze at an initial point (0, 0) (the maze can be thought of as a 2-dimensional plane). The maze would be given in the form of a squar...read more
You are given a Singly Linked List of integers. Sort the Linked List using merge sort.
Merge Sort is a Divide and Conquer algorithm. It divides the input into two halves, calls itself for ...read more
You are 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 of each other or not.
Two trees a...read more
You are given an integer array with N elements. Your task is to build a max binary heap from the array.
A max-heap is a complete binary tree in which the value of each internal node is greater than or...read more
There are ‘N’ houses in a village. Ninja wants to supply water for all the houses by building wells and laying pipes.
For each house ‘i’, we can either build a well inside it directly w...read more
Ninja is given a task to implement a priority queue using Heap data structure. The Ninja is busying preparing for the tournament., So he asked for your help.
Your task is to use the cl...read more
Q93. What is FSM and explain the differences between the Mealy and Moore machines?
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
You are given a positive integer 'N'. You have to generate all possible sequences of balanced parentheses using 'N' pairs of parentheses.
A sequence of brackets is called balan...read more
Q95. 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.
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
Given an integer N, find value of XoR of all integers from 1 to N.
Sample Case:-
Input : n = 6
Output : 7
// 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 = 7
Input : n = 7
Output : 0
// 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 ^ 7 = 0
You are given a binary tree having 'N' nodes. Each node of the tree has an integer value. Your task is to find the maximum possible sum of a simple path between any two nodes (...read more
Given a graph, check whether the graph is bipartite or not. Your function should return true if the given graph's vertices can be divided into two independent sets, ‘U’ and ‘V’ su...read more
Q99. Draw the CMOS inverter circuit and derive the transfer characteristics of inverter.What are the regions of operations of it?
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
Q100. What do you think is an area of improvement for you?
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
More about working at Samsung
Top HR Questions asked in null
Interview Process at null
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month