Please read the new rule regarding the restriction on the use of AI tools. ×

Minimum number of student remaining

Revision en2, by gaand_na_phulao, 2020-06-15 18:51:06

Yesterday I had a Samsung test. There a question which I wasn't able to solve. The question was like this

You have given n student with their id. Students are standing in a queue. You have also an integer k. You can remove the students such that their id follows this rule:

  • arr[i-1]+k=arr[i]=arr[i+1]-k .(All three students will be removed from the queue).

You have to remove these students such that the minimum number of student will be remaining at the end.

Constraints: 1<=t<=20 3<=n<=100. 1<=arr[i]<=10^6. 1<=k<=10^6.

Input : 2 6 1 3 4 5 6 7 5 5 1 1 2 3 4 5

Output: 0 2

Explanation: In the first test case, If we remove 5 6 7 then the remaining array will be 3 4 5. Now again I can remove these students. So the minimum number of student remaining will be 0.

In second test case, we can remove more than three students from the queue. So the remaining number of students will be 2.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en19 English gaand_na_phulao 2020-06-15 19:13:18 0 (published)
en18 English gaand_na_phulao 2020-06-15 19:12:56 14 (saved to drafts)
en17 English gaand_na_phulao 2020-06-15 19:10:37 1 Tiny change: 'nts follows this rule' -> 'nts follow this rule' (published)
en16 English gaand_na_phulao 2020-06-15 19:09:52 26 (saved to drafts)
en15 English gaand_na_phulao 2020-06-15 19:07:26 0 (published)
en14 English gaand_na_phulao 2020-06-15 19:06:58 54 (saved to drafts)
en13 English gaand_na_phulao 2020-06-15 19:05:12 0 (published)
en12 English gaand_na_phulao 2020-06-15 19:03:52 0 Tiny change: ' queue).\n\nYou ha' -> ' queue).\n- You can\n\nYou ha'
en11 English gaand_na_phulao 2020-06-15 19:02:55 3
en10 English gaand_na_phulao 2020-06-15 19:02:26 8
en9 English gaand_na_phulao 2020-06-15 19:01:45 8
en8 English gaand_na_phulao 2020-06-15 19:00:59 2 Tiny change: 'se, we can remove mo' -> 'se, we can't remove mo'
en7 English gaand_na_phulao 2020-06-15 18:58:59 7
en6 English gaand_na_phulao 2020-06-15 18:57:23 115
en5 English gaand_na_phulao 2020-06-15 18:53:48 10
en4 English gaand_na_phulao 2020-06-15 18:52:51 14
en3 English gaand_na_phulao 2020-06-15 18:52:07 29
en2 English gaand_na_phulao 2020-06-15 18:51:06 32
en1 English gaand_na_phulao 2020-06-15 18:49:11 944 Initial revision (saved to drafts)