## Samsung Interview Questions

- 0of 0 votes
given an array of integers suppose 1234, print all groups of integer array possible of length upto n where n can be any number greater than zero

example for n=5

1,11,111,1111,11111,12341,22222,2222,222,22,2 etc

for n=3

1,11,123 etc

- 0of 0 votes
Company S has developed an industrial endoscope available to explore inner part of the decrepit water pipes. It is possible to explore the inner part of the pipes putting the endoscope in a certain part of the pipe. The endoscope can be moved in the pipe only. Meanwhile, when the pipes are connected to each other, if the length of the endoscope is long enough to explore ,then it is able to inspect the connected pipes. However, we cannot observe every pipe because the length of endoscope is limited.

When the map of the ground water pipe, the location where the endoscope to out in, and the length of the endoscope is given, calculate the number of pipe which are available to explore. Length of endoscope means the range upto which endoscope can explore. There are seven kind of pipes, and description for each pipe are shown below:

S.No Pipe Connected to

1 Up, Down, Left, Right

2 Up, Down

3 Left, Right

4 Up, Right

5 Down, Right

6 Down, Left

7 Up, Left

When the map of the ground water pipe, the location where the endoscope to out in, and the length of the endoscope is given, calculate the number of pipe which are available to explore. Length of endoscope means the range upto which endoscope can explore.

Input

In the first line, T, the number of total test cases is given. From the second line, T test cases are given. In the first line of each test case, N, the height of the map of the ground water pipes, M, the width, R, the vertical location of the water pipe where to put in the endoscope, C, the horizontal location of it, and the length of the endoscope L are given. In the following N lines information of the map of ground water pipe is given. Each line has M numbers. Each number (from 1 to 7) means the type of water pipe for that point. 0 means there is no water pipe buried in that place.

Output

Print the respective answer for T test cases in total for T lines. The answer is the number of water pipes which is available to observe using the endoscope.

Constraints

1≤ T ≤100

1≤ N, M ≤50

0≤ X < N

0≤ Y < M

1≤ L ≤ 20

- 0of 0 votes
A Research team want to establish a research center in a region where they found some rare-elements. They want to make it closest to all the rare-elements as close as possible so that they can reduce overall cost of research over there. It is given that all the rare-element’s location is connected by roads. It is also given that Research Center can only be build on road. Team decided to assign this task to a coder. If you feel you have that much potential..

Here is the Task :- Find the shortest of the longest distance of research center from given locations of rare-elements.

Locations are given in the matrix cell form where 1 represents roads and 0 no road..

Number of rare-element and their location was also given(number<=5)

and order of square matrix was less than equal to (20).

- 0of 0 votes
Given number of pipes 1..n, Find two largest pipes of maximum length possible.

Ex: input - 1,2,3,4,6

Output - The maximum length possible is 8.

Pipe1 - 2,6

Pipe2 - 1,3,4

- -2of 2 votes
There was given total physical energy H and total distance D. Five pace information speed and corresponding physical energy was given. Find the minimum time that is required in order to complete total distance D making sure that some of the physical energy does not exceed H

- 0of 0 votes
This was a 3 hours coding round in which we had to code 1 problem having 50 test cases. Only those students were selected for the next round who passed all the test cases. Here is the question:

You’ll be given a grid as below:

0 1 0 2 0

0 2 2 2 1

0 2 1 1 1

1 0 1 0 0

0 0 1 2 2

1 1 0 0 1

x x S x x

In the grid above,

1: This cell has a coin.

2: This cell has an enemy.

0: It contains nothing.

The highlighted(yellow) zone is the control zone. S is a spaceship that we need to control so that we can get maximum coins.

Now, S’s initial position will be at the center and we can only move it right or left by one cell or do not move.

At each time, the non-highlighted part of the grid will move down by one unit.

We can also use a bomb but only once. If we use that, all the enemies in the 5×5 region above the control zone will be killed.

If we use a bomb at the very beginning, the grid will look like this:

0 1 0 2 0

0 0 0 0 1

0 0 1 1 1

1 0 1 0 0

0 0 1 0 0

1 1 0 0 1

x x S x x

As soon as, the spaceship encounters an enemy or the entire grid has come down, the game ends.

For example,

At the very first instance, if we want to collect a coin we should move left( coins=1). This is because when the grid comes down by 1 unit we have a coin on the second position and by moving left we can collect that coin. Next, we should move right to collect another coin( coins=2).

After this, remain at the same position( coins=4).

This is the current situation after collecting 4 coins.

0 1 0 2 0 0 1 0 0 0

0 2 2 2 1 -->after using 0 0 0 0 1

x x S x x -->bomb x x S x x

Now, we can use the bomb to get out of this situation. After this, we can collect at most 1 coin. So maximum coins=5.

- 1of 1 vote
You are given an old touch smartphone numbers having dial pad and calculator app.

Aim: The goal is to type a number on dialpad.

But as phone is old, some of the numbers and some operations can't be touched.

For eg. 2,3,5,9 keys are not responding , i.e you cannot use them

But you can always make a number using other numbers and operations in Calculator. There could be multiple ways of making a number

.Calculator have 1-9 and +,-,*,/,= as operations. Once you have made the number in Calculator you can copy the number and use it.

You have to find minimum number to touches required to obtain a number.

#Input:#

There will be multiple Test cases .Each test case will consist of 4 lines

1) First line will consist of N,M,O

N: no of keys working in Dialpad (out of 0,1,2,3,4,5,6,7,8,9)

M:types of operations supported (+,-,*,/)

O: Max no of touches allowed

2) second line of input contains the digits that are working e.g 0,2,3,4,6.

3) Third line contains the valued describing operations, 1(+),2(-),3(*),4(/)

4) fourth line contains the number that we want to make .

#Output:#

Output contains 1 line printing the number of touches required to make the number

#Sample Test Case:#

1 // No of test cases

5 3 5 // N ,M, O

1 2 4 6 0 // digits that are working (total number of digits = N),

1 2 3 // describing operations allowed (1--> '+', 2--> '-', 3--> '*' , 4--> '/' )(total number is equals to M)

5 // number we want to make

Answer 3

How 4? 1+4= , "=" is also counted as a touch

2nd Sample Case

3 // No of Test cases

6 4 5 // N ,M, O

1 2 4 6 9 8 // digits that are working (total number of digits = N),

1 2 3 4 // describing operations allowed (1--> +, 2--> -, 3--> , 4-->/)

91 // number we want to make

6 2 4 // 2nd test case

0 1 3 5 7 9

1 2 4 // +, -, / allowed here

28

5 2 10

1 2 6 7 8

2 3 // -, allowed

981

#Output:#

2 // 91 can be made by directly entering 91 as 1,9 digits are working, so only 2 operations

5// 35-7=, other ways are 1+3*7=

9//62*16-11=

Order for computation will be followed as symbols entered, if + comes, it will be computed first

One more example: lets say 1,4,6,7,8,9 works and +,-,* works.

2,3,5 and / doesn't work.

If you have to type 18-> 2 operations. (Each touch is considered an operation),br> If you have to type 5 -> '1+4=' that requires 4 operations. There could be other ways to make '5'.

- 0of 2 votes
There is an island surrounded by oil mines. You will be given n companies and m oil mines having values. You have to distribute the mines to "n" companies in fair manner. Remember the companies can have oil mines adjacent to each other and not in between of each others.After distributing them compute the differnce of oil mines from the company getting highest and company getting lowest. This number should be minimum.(then only the distribution can be termed as fair).

Example

Input

2

2 4

6 13 10 2

2 4

6 10 13 2

output

5

1

- 0of 0 votes
There is dedicated Samsung software for coding test the question is given below:

There is one spaceship. X and Y co-odinate of source of spaceship and destination spaceship is given. There are N number of warmholes each warmhole has 5 values.

First 2 values are starting co-ordinate of warmhole and after that value no. 3 and 4 represents ending co-ordinate of warmhole and last 5th value is represents cost to pass through this warmhole. Now these warmholes are bi-direction.

Now the to go from (x1,y1) to (x2,y2) is abs(x1-x2)+abs(y1-y2).

The main problem here is to find minimum distance to reach spaceship from source to destination co-ordinate using any number of warm-hole. It is ok if you wont use any warmhole.

- 1of 1 vote
Mr. Kim has to deliver refrigerators to N customers. From the office, he is going to visit all the customers and then return to his home. Each location of the office, his home, and the customers is given in the form of integer coordinates (x,y) (0≤x≤100, 0≤y≤100) . The distance between two arbitrary locations (x1, y1) and (x2, y2) is computed by |x1-x2| + |y1-y2|, where |x| denotes the absolute value of x; for instance, |3|=|-3|=3. The locations of the office, his home, and the customers are all distinct. You should plan an optimal way to visit all the N customers and return to his among all the possibilities.

You are given the locations of the office, Mr. Kim’s home, and the customers; the number of the customers is in the range of 5 to 10. Write a program that, starting at the office, finds a (the) shortest path visiting all the customers and returning to his home. Your program only have to report the distance of a (the) shortest path.

You don’t have to solve this problem efficiently. You could find an answer by looking up all the possible ways. If you can look up all the possibilities well, you will get a perfect score.

[Constraints]

5≤N≤10. Each location (x,y) is in a bounded grid, 0≤x≤100, 0≤y≤100, and x, y are integers.

[Input]

You are given 10 test cases. Each test case consists of two lines; the first line has N, the number of the customers, and the following line enumerates the locations of the office, Mr. Kim’s home, and the customers in sequence. Each location consists of the coordinates (x,y), which is reprensented by ‘x y’.

[Output]

Output the 10 answers in 10 lines. Each line outputs the distance of a (the) shortest path. Each line looks like ‘#x answer’ where x is the index of a test case. ‘#x’ and ‘answer’ are separated by a space.

[I/O Example]

Input (20 lines in total. In the first test case, the locations of the office and the home are (0, 0) and (100, 100) respectively, and the locations of the customers are (70, 40), (30, 10), (10, 5), (90, 70), (50, 20).)

5 ← Starting test case #1

0 0 100 100 70 40 30 10 10 5 90 70 50 20

6 ← Starting test case #2

88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14

10 ← Starting test case #3

39 9 97 61 35 93 62 64 96 39 36 36 9 59 59 96 61 7 64 43 43 58 1 36

...

Output (10 lines in total)

#1 200

#2 304

#3 366

- 1of 1 vote
You are given an old touch smartphone numbers having dial pad and calculator app.

The goal is to type a number on dialpad.

Calculator have 1-9 and +,-,*,/,= as operations. But as phone is old, some of the numbers and some operations can't be touched.

But you can always make a number using other numbers and operations. There could be multiple ways of making a number. You have to find minimum operation for making a number.

For ex: lets say 1,4,6,7,8,9 works and +,-,* works.

2,3,5 and / doesn't work.

If you have to type 18-> 2 operations. (Each touch is considered an operation)

If you have to type 5 -> '1+4=' that requires 4 operations. There could be other ways to make '5'.

The goal is to find minimum operations.

- 1of 1 vote
there is a file and 5 processes

how can you grant access so that

only 2 process can write to file and 1 can read file at a time

in linux

- 0of 0 votes
A delivery boy wants to deliver some items on his way from office to home. You need to find the optimized path he should take from office to home and deliver all his deliveries on his way.

It is 101 X 101 grid. Office, home , delivery points are represented via coordinated (x,y) where 0 <= x <= 100, 0 <= y <= 100.

distance between two points (x1, y1) and (x2,y2) is computed as |x1 - x2| + |y1 - y2|

You need to find the optimized path from office to home covering all delivery locations and return the optimized path length as output.

You will be given the input in the 2 lines

first line - N (no. of delivery locations)

second line - (x,y) coordinates of office, followed by home, followed by all N delivery locations.

3

0 0 100 100 20 30 50 50 70 70

output: The length of the optimized path taken.

For above input, the output is 200

- 1of 1 vote
WAP to get following.

input : {2, 4, 3, 5, 6}

output: {360, 180, 240, 144, 120 }

Hint: {4*3*5*6, 2*3*5*6, 2*4*5*6, 2*4*3*5}

Please note, division is not allowed and time complexity should be O(N).

- 0of 0 votes
There are N pots. Every pots has some water in it. They may be partially filled . Every pot is associated with overflow number O which tell how many minimum no. of stones required for that pot to overflow. The crow know O1 to On(overflow no. for all the pots). Crow wants some K pots to be overflow. So the task is minimum number of stones he can make K pots overflow in worst case.

Array of overflow no--. {1,...On}

Number of pots--n

No of pots to overflow-- k

Let say two pots are there with overflow no.s {5,58}, and crow has to overflow one pot(k=1). So crow will put 5 stones in pot with overflow no.(58), it will not overflow, then he will put in pot with overflow no.(5), hence the total no. of stones to make overflow one pot is=10.

What are the best algorithm to do it?

- 0of 0 votes
`You are given an mxn grid, where (0,0) refers top most left position and (m-1,n-1) the bottom most right. The grid is filled with ones. All positions in the grid that are blocked are filled with zeros. You are given this grid and are assured that there exists atleast one path from (0,0) to (m-1, n-1). Find the minimum distance of the path from (0,0) to (m-1, n-1) given that you are allowed to move only vertically, horizontally and diagonally`

- 0of 0 votes
Check if tree is BST.

- 1of 1 vote
We have a char array and we need to reverse it. say Char Array is “Northern California USA”, need to print “USA California Northern”. Can’t use any other data structures or buffer. Can only use a char temp.

- 0of 0 votes
Find the kth minimum element into binary search.

- 0of 0 votes
We have array of strings. Go through each element of array and eliminate duplicates if any string is having. You have to save in the same array.

- 0of 0 votes
What is memory alignment in terms of compiler

- 0of 0 votes
what are types of memory issues one faces

- 0of 0 votes
Write a program to find 2 complement of number

- 0of 0 votes
How can we use union find algorithm for finding the path between two points in a Maze

- -3of 3 votes
I have two number A = 100 and B = 145;

I want to find all number that have digit of number is increase

Thanks

- 4of 4 votes
We have 25 horses and we need to find top 5 fastest horses irrespective of order, in a race only 5 horse can run. how many min races required to know top 5 horses...out of top 5 ordering not matter...u not need to tell which is fastest which is at second position.....

- 0of 0 votes
Write an application in Java to simulate file system. For e.g. implement commands: ls -l (list contents of director sorted by name), cd .. (to go to parent directory), etc. It was a 2 hour remote programming test.

- 0of 0 votes
How you can find whether a link list contains a cycle or not?

- 0of 0 votes
Show whether two integer ranges are overlapping or not. If so, return the overlap range

- 0of 0 votes
find a cycle in the given array and return the length of a cycle

for example, a[0] = 2, a[1] = 0, a[2] = 3, a[3] = 1, a[4] = 2, a[5] =4;

a[0]=2 -> a[2]=3 -> a[3]=1 -> a[1] =0 -> a[0]=2 ....

2->3-1>0->2->3->1->0->...

so return value should be 3.