Samsung interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

Samsung
upvote
share-icon
4 rounds | 12 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 Months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Campus
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Online Coding Test
Duration120 Minutes
Interview date18 Aug 2021
Coding problem3

This was an online coding round where we had 3 questions to solve under 120 minutes. The questions were of medium to hard difficulty level.

1. Trapping Rain Water

Moderate
15m average time
80% success
0/80
Asked in companies
HCL TechnologiesCiti BankAtlassian

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.



Note :
The width of each bar is the same and is equal to 1.
Example:
Input: ‘n’ = 6, ‘arr’ = [3, 0, 0, 2, 0, 4].

Output: 10

Explanation: Refer to the image for better comprehension:

Alt Text

Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Problem approach

Approach :

1) Create two lists or arrays, say, ‘leftMax’ and ‘rightMax’.
2) At every index in the ‘leftMax’ array store the information of the ‘leftMaxHeight’ for every elevation in the map.
3) Similarly, at every index in the ‘rightMax’ array store the information of the ‘rightMaxHeight' for every elevation in the map.
4) Iterate over the elevation map and find the units of water that can be stored at this location by getting the left max height and right max height from the initial arrays that we created.

TC : O(N), where N=total number of elevations in the map.
SC : O(N)

Try solving now

2. Shortest Path in a Binary Matrix

Moderate
37m average time
65% success
0/80
Asked in companies
SprinklrCIS - Cyber InfrastructureMakeMyTrip

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.

Your task is to find the length of the shortest path from the source cell to the destination cell only consisting of 1s. If there is no path from source to destination cell, return -1.

Note:
1. Coordinates of the cells are given in 0-based indexing.
2. You can move in 4 directions (Up, Down, Left, Right) from a cell.
3. The length of the path is the number of 1s lying in the path.
4. The source cell is always filled with 1.
For example -
1 0 1
1 1 1
1 1 1
For the given binary matrix and source cell(0,0) and destination cell(0,2). Few valid paths consisting of only 1s are

X 0 X     X 0 X 
X X X     X 1 X 
1 1 1     X X X 
The length of the shortest path is 5.
Problem approach

Approach (Using BFS) :

1) Create an empty queue and enqueue source cell and mark it as visited

2) Declare a ‘STEPS’ variable, to keep track of the length of the path so far

3) Loop in level order till the queue is not empty
3.1) Fetch the front cell from the queue
3.2) If the fetched cell is the destination cell, return ‘STEPS’
3.3) Else for each of the 4 adjacent cells of the current cell, we enqueue each valid cell into the queue and mark them visited.
3.4) Increment ‘STEPS’ by 1 when all the cells in the current level are processed.

4) If all nodes in the queue are processed and the destination cell is not reached, we return -1.

TC : O(N*M) , where ‘N’ and ‘M’ are the number of rows and columns in the Binary Matrix respectively. 
SC : O(N*M)

Try solving now

3. Count Leaf Nodes

Easy
10m average time
90% success
0/40
Asked in companies
SamsungOlaSlice

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 referred to as the left child and the right child

A node is a leaf node if both left and right child nodes of it are NULL.

Problem approach

Approach : 

1) Given a tree node ROOT, initialise a queue of nodes NODEQUEUE and COUNT by 0.

2) Push ROOT into NODEQUEUE.

3) While NODEQUEUE is not empty do:
3.1) Initialize node TEMP as NODEQUEUE.peek().
3.2) If TEMP.left is not NULL, push TEMP.left to NODEQUEUE.
3.3) If TEMP.right is not NULL, push TEMP.right to NODEQUEUE.
3.4) If TEMP.right and TEMP.left are both NULL, increase COUNT by 1.

4) Return COUNT

TC : O(N), where N=number of nodes in the tree.
SC : O(N)

Try solving now
02
Round
Medium
Video Call
Duration60 Minutes
Interview date19 Aug 2021
Coding problem4

In this round I was first asked 2 questions related to DSA where I was expected to first explain my approach to the interviewer along with proper complexity analysis and then code the implementation in any of my preferred IDE. This was followed by some questions related to OOPS and C++.

1. Find The Repeating And Missing Number

Easy
10m average time
90% success
0/40
Asked in companies
AmazonSamsungPhonePe

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 missing. You need to determine the repeating and the missing integer.

Example:
Let the array be [1, 2, 3, 4, 4, 5]. In the given array ‘4’ occurs twice and the number ‘6’ is missing.
Problem approach

Approach 1 :

1) We use a count array to store the frequency.
2) We initialize the count array to zero for all the numbers.
3) Now, iterate through the array and increment the corresponding frequency count of the numbers.
4) Now, we iterate through the count (frequency) array.
5) The number with a frequency equal to zero is the missing number while the number with a frequency equal to two
is the repeating number.

TC : O(N), where N=size of the array
SC : O(N)


Approach 2 :

1) Traverse the array and mark the index corresponding to the current number.
2) While traversing if the index corresponding to the current number has already been marked. Then the current
number is the repeating number in the array.
3) In order to determine the missing number, traverse the array again and look for a positive value.
4) The index corresponding to the positive number gives us the missing number (= index + 1).

TC : O(N), where N=size of the array
SC : O(1)

Try solving now

2. Number Of Pairs With Given Sum

Moderate
39m average time
60% success
0/80
Asked in companies
Goldman SachsAmazonSamsung

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:
Given array/list can contain duplicate elements.

(arr[i],arr[j]) and (arr[j],arr[i]) are considered same.
Problem approach

Approach : 

1) Create a hashmap/dictionary which will store the count of occurrences of each element and initially it will be empty.

2) Run a loop from i=0 to N-1 and for each i’th element its value is arr[i] and we need to find the number which is equal to Sum - arr[i]. So check if sum-arr[i] is present in the hashmap/dictionary. If it is present, the answer will be increased by the count of occurrence of sum-arr[i] present in the hashmap/dictionary as arr[i] can be paired with all those sum-arr[i] elements present in its left side.

3) Now increase the count of arr[i] in the hashmap/dictionary by 1.

TC : O(N), where N=size of the array
SC : O(N)

Try solving now

3. DS Question

Difference between structure and union and what are the pros and cons of both?

Problem approach

Answer :

Structure : Structure is a user-defined data type in C programming language that combines logically related data
items of different data types together.
All the structure elements are stored at contiguous memory locations. Structure type variable can store more than
one data item of varying data types under one name.

Union : Union is a user-defined data type, just like a structure. Union combines objects of different types and sizes
together. The union variable allocates the memory space equal to the space to hold the largest variable of union. It
allows varying types of objects to share the same location.


Key differences b/w Structure and Union :

1) Every member within structure is assigned a unique memory location while in union a memory location is shared
by all the data members.
2) Changing the value of one data member will not affect other data members in structure whereas changing the
value of one data member will change the value of other data members in union.
3) Structure is mainly used for storing various data types while union is mainly used for storing one of the many data
types.
4) In structure, you can retrieve any member at a time on the other hand in union, you can access one member at a
time.
5) Structure supports flexible array while union does not support a flexible array.


Advantages and Disadvantages of using Structure :

Advantages :
1) Structures gather more than one piece of data about the same subject together in the same place.
2) It is helpful when you want to gather the data of similar data types and parameters like first name, last
name, etc.
3) It is very easy to maintain as we can represent the whole record by using a single name.

Disadvantages :
1 )If the complexity of IT project goes beyond the limit, it becomes hard to manage.
2) Change of one data structure in a code necessitates changes at many other places. Therefore, the
changes become hard to track.
3) Structure is slower because it requires storage space for all the data.


Advantages and Disadvantages of using Union :

Advantages :
1) It occupies less memory compared to structure.
2 )When you use union, only the last variable can be directly accessed.
3) Union is used when you have to use the same memory location for two or more data members.

Disadvantages :
1) You can use only one union member at a time.
2) All the union variables cannot be initialized or used with varying values at a time.
3) Union assigns one common storage space for all its members.


Tip : Cover concepts of OOPS properly preferrably in C++ or in Java and for quick revision, the guided path of C++ in
Coding Ninjas is a very good resource. I completed the OS and C++ guided path before my interviews and it helped
me a lot.

4. OOPS Question

How does C++ support Polymorphism?

Problem approach

C++ is an Object-oriented programming language and it supports Polymorphism as well:

Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features like templates, function overloading, and default arguments.

Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual functions. Virtual functions take the shape of the functions based on the type of object in reference and are resolved at runtime.

03
Round
Medium
Video Call
Duration60 Minutes
Interview date19 Aug 2021
Coding problem5

This round had 3 questions from DSA which I had to code under 60 minutes and then the interviewer asked some questions from Operating Systems and Android as I did a project in Mobile App Development.

1. Spiral Order Traversal of a Binary Tree

Easy
20m average time
75% success
0/40
Asked in companies
PayUAtlassianAmazon

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, -1, -1]
    1
   / \
  2   3
     / \
    4   5

Output: 1 3 2 4 5
Problem approach

Approach : 

1) We will maintain two stacks, one for each direction i.e. leftToRight and rightToleft.

2) We will do a level order traversal of the given binary tree and push nodes of each level onto one of the stack according to the current direction of traversal.

3) After we’ve pushed all nodes of a level onto one stack, we’ll start popping those nodes. While popping the nodes we will push their children (if any) onto our other direction stack, so that the next level be traversed in reverse order.

TC : O(N), where ‘N’ is the number of nodes in the binary tree.
SC : O(N)

Try solving now

2. Stack using queue

Moderate
25m average time
65% success
0/80
Asked in companies
AmazonQualcommPhilips

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


Implement the following public functions :

1. Constructor:
It initializes the data members(queues) as required.

2. push(data) :
This function should take one argument of type integer. It pushes the element into the stack and returns nothing.

3. pop() :
It pops the element from the top of the stack and, in turn, returns the element being popped or deleted. In case the stack is empty, it returns -1.

4. top :
It returns the element being kept at the top of the stack. In case the stack is empty, it returns -1.

5. size() :
It returns the size of the stack at any given instance of time.

6. isEmpty() :
It returns a boolean value indicating whether the stack is empty or not.
Operations Performed on the Stack:
Query-1(Denoted by an integer 1): Pushes an integer data to the stack. (push function)

Query-2(Denoted by an integer 2): Pops the data kept at the top of the stack and returns it to the caller. (pop function)

Query-3(Denoted by an integer 3): Fetches and returns the data being kept at the top of the stack but doesn't remove it, unlike the pop function. (top function)

Query-4(Denoted by an integer 4): Returns the current size of the stack. (size function)

Query-5(Denoted by an integer 5): Returns a boolean value denoting whether the stack is empty or not. (isEmpty function)
Example
Operations: 
1 5
1 10
2
3
4

Enqueue operation 1 5: We insert 5 at the back of the queue.
  Queue: [5]

Enqueue operation 1 10: We insert 10 at the back of the queue.
  Queue: [5, 10]

Dequeue operation 2: We remove the element from the front of the queue, which is 5, and print it.
  Output: 5
  Queue: [10]

Peek operation 3: We return the element present at the front of the queue, which is 10, without removing it.
  Output: 10
  Queue: [10]

IsEmpty operation 4: We check if the queue is empty.
  Output: False
  Queue: [10]
Problem approach

Approach : A stack can be implemented using two queues. Let stack to be implemented be ‘s’ and queues used to implement be ‘q1’ and ‘q2’. Stack ‘s’ can be implemented in two ways :

Method 1 (push - O(1) , pop - O(n) ) :

1) push(s, x) operation :
i) Enqueue x to q1 (assuming size of q1 is unlimited).

2) pop(s) operation :
i) One by one dequeue everything except the last element from q1 and enqueue to q2.
ii) Dequeue the last item of q1, the dequeued item is result, store it.
iii) Swap the names of q1 and q2
iv) Return the item stored in step 2.

TC : push(s,x) -> O(1)
pop() -> O(n)


Method 2 (push - O(n) , pop - O(1) ) :

1) push(s, x) operation :
i) Enqueue x to q2
ii) One by one dequeue everything from q1 and enqueue to q2.
iii) Swap the names of q1 and q2

2) pop(s) operation :
i) Dequeue an item from q1 and return it.

TC : push(s,x) -> O(n)
pop() -> O(1)

Try solving now

3. Convert a binary tree to its sum tree

Easy
15m average time
85% success
0/40
Asked in companies
AmazonMicrosoftSamsung

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 right subtrees in the given tree. The value of leaf nodes is changed to zero.

Example:
Below is the example showing the input tree and its sum tree.  

alt text

Problem approach

Approach : 

1) Traverse a given binary tree.
2) While traversing the given binary tree, store the old value of the current node, recursively call for left and right subtrees.
3) Now change the value of the current node as the sum of the values returned by the recursive calls of left and right subtrees.
4) Finally, return the sum of the new value and value (which is the sum of values in the subtree rooted with this node).

TC : O(N), where ‘N’ is the number of nodes in the given binary tree.
SC : O(N)

Try solving now

4. OS Question

What is meant by Multitasking and Multithreading in OS?

Problem approach

Answer :

Multitasking : It refers to the process in which a CPU happens to execute multiple tasks at any given time. CPU
switching occurs very often when multitasking between various tasks. This way, the users get to collaborate with
every program together at the same time. Since it involves rapid CPU switching, it requires some time. It is because
switching from one user to another might need some resources. The processes in multi-tasking, unlike multi-
threading, share separate resources and memories.


Multithreading : It is a system that creates many threads out of a single process to increase the overall power and
working capacity of a computer. In the process of multi-threading, we use a CPU for executing many threads out of a
single process at any given time. Also, the process of creation depends entirely on the cost. The process of
multithreading, unlike multitasking, makes use of the very same resources and memory for processing the execution.

5. Technical Question

What is Android?

Problem approach

Android is an open-sourced operating system that is used on mobile devices, such as mobiles and tablets. The Android application executes within its own process and its own instance of Dalvik Virtual Machine(DVM) or Android RunTime(ART).

04
Round
Easy
HR Round
Duration30 Minutes
Interview date19 Aug 2021
Coding problem0

This was about 30 minutes long interview. First, she asked introduction, after that she was very interested in my internship that I did in summer and about my interests. She asked few common questions on that.

Tip : Please ask questions at the end of session when they ask you to do so. In the end, she asked if I had any
questions for her and I asked how is life working in Samsung, how long she was working and in which domain. The interview went well in the end.

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

How do you remove whitespace from the start of a string?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
4 rounds | 6 problems
Interviewed by Samsung
1921 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 4 problems
Interviewed by Samsung
1221 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 6 problems
Interviewed by Samsung
2229 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 5 problems
Interviewed by Samsung
419 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
115097 views
24 comments
0 upvotes
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
58237 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35147 views
7 comments
0 upvotes