Skip to content
Related Articles

Related Articles

Improve Article

Samsung R&D Bangalore Interview Experience | Lateral hire (6 month experience)

  • Difficulty Level : Medium
  • Last Updated : 21 Jan, 2020

It was a Professional level coding test, where we were given 4 hours to solve One problem.

There is a highway that has damages at N (4<=N<=100) locations. Each damage location is represented by a number a (0<=a<=10000). You need to repair these damages with Asphalt. The damage is repaired with these rules:

  1. Asphalt can be spread on the road with a minimum stretch of K (1<=K<=10000) i.e. each time you put asphalt, it will be spread to k consecutive locations. eg. if the damage is at locations 2, 5 and K=3 then the first asphalt spread is from 0-2 or 1-3 or 2-4 and the second is from 3-5 or 4-6 or 5-7.
  2. You need to spread minimum Asphalt to repair all damaged locations of the road. For the above example, the minimum asphalt required is 4 units ( 2-4 and 3-5) because 3-4 is overlapping.

Example test cases:

Input:-

N K



A[0] A[1] …….. A[N-1]

Output:-

Minimum Asphalt area to repair all damages.

1.

10 2

0 10 2 12 4 14 6 16 8 18

output: 15

2.

4 3

3 9 11 8

output: 7

3.

8 3

2  7 20 5 19 9 6 22

output: 12

Please let me know if there is any confusion in the question!!

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, Amazon. GoogleE-Litmus and Microsoft Test Serieses.

My Personal Notes arrow_drop_up
Recommended Articles
Page :