# Samsung Interview Experience for (SRI-B) Internship

• Difficulty Level : Expert
• Last Updated : 23 Sep, 2020

Coding Round: There were 3 questions to be solved within 70 minutes.

1. A 2D matrix is given to you, and you have to sort the matrix row-wise.
2. A binary tree is given to you and you have to replace the data value of all the nodes with the sum of data of its subtree excluding the node itself.
3. A company(say Samsung) need some employees to maintain its business. Due to up-downs in business, the number of employees required changes every month. An array A[] of length N is given to you where each i [1, N] signifies the minimum number of employees required in the i-th month. The company may hire some employees with cost HIRE and fire some employees with severance pay S. SALARY is the salary of the employees in each month.

Now you have to find MINIMUM COST TO COMPANY so that the Company can run for N months. Initially, the Company has 0 employees.

Constraints are given:

```1 <= A[i] <= 41
```

Sample:

```Input: A[] = {10, 5, 6, 2}
HIRE = 10
S = 15
SALARY = 10
Output:440
```
```Explanation:
Month 1 : hire 10 employee cost till now (10+10)×10 = 200
Month 2 : fire 4 employee cost till now 200 + 4×15 + 6×10 = 320
Month 3 : no hire no fire cost till now = 320 + 6×10 = 380
Month 4 : no hire no fire cost till now = 380 + 60 = 440
Thus, minimum cost to company = 440
```

Hint: Just brute force all possible cases.

I had solved all three problems. For the first problem since constraints were not given, I just did brute force in O(N^3).

Round 1(Personal Interview): The interviewer asked me to introduce myself, then asked me to explain my projects. Then he asked a coding question

Coding Question:

1. You are given a natural number N(N<=1e8), and an array of M integers A, You have to find how many numbers from 1 to N(both inclusive) is divisible by any of the array elements.

Solution Approach: iterate over all the subsets of the array. If there are an odd number of elements in the subset then add its contribution else subtract it (Inclusion-Exclusion principle).

(I had to write code for this solution)

2. This was just an extension of the previous problem. You are given an array of M elements, you have to find the K-th element which is divisible by any of the array elements.

Solution Approach: Same as the previous one. Just binary search over the numbers to find the K-th element.

Then the interviewer asked some more C/C++ oriented questions.

1. What is the forward function in C++?
2. What are derived data types in C?

(I could not answer both the above question but solved the coding questions)

• You are given N strings. You have to find 100 strings which have occurred the most number of times.

Hint: The best solution is using trie and min-heap.

I had given him 3 approaches.

• First Approach: Just applied brute force.
• Second Approach: Comparision of the strings can be done using Hashing just an improvement of the first approach.
• Third Approach: Using the Trie data structure.

He was quite satisfied with me.

Tips: Coding helps a lot. Doing Competitive programming on codeforces and codechef helped me THE MOST in the selection.

My Personal Notes arrow_drop_up