You are not logged in. Please login at to post your questions!


SNACKUP. why cant k be 2 for every case?

In SNACKUP why cant i set k=2 for all the values of n as it is mentioned that we can select k that is no. of judges invited arbitrarily. Selecting k=2 will gave same answer for all values of n. Why is this not possible.

asked 19 Jun '17, 01:28

sarthak_1995's gravatar image

accept rate: 0%

The problem statement was purposely made large to make participants think of it as a hard problem. (Due to which i SKIPPED doing it till end...GOSH!!)

The problem said that, you can organize ANY number of rounds, inviting ANY number of judges (upto N, of course). Every round, Ada will make 2 x k dishes dishes. Every dish must be eaten, and a judge cannot eat same dish twice, AND a judge cannot eat more than 2 dishes.

At the end of all the rounds, the statistics should be such that EVERY JUDGE TASTED EVERY DISH EXACTLY TWICE.

What i came up with, was to hold N rounds, invite ALL N judges, and make then eat dishes as-

For 1st round-

Judge 1-  (1,2)
Judge 2- (2,3)
Judge 3- (3,4)
Judge N-1 - (N-1,N)
Judge N - (N,1)

For second round-

(Shift the order of dishes 1 place up)

Judge 1 -(2,3)
Judge 2- (3,4)
Judge 3- (4,5)
Judge N-1 -(N,1)
Judge N- (1,2)

This is one of the easiest solution to this problem. I hope i made the pattern clear. In case of any further doubts, let me know ^^


answered 19 Jun '17, 07:08

vijju123's gravatar image

5★vijju123 ♦
accept rate: 18%

As @hikarico has rightly said, if you set k=2 you are focusing only on the even number of judges. N matters in your case because if you are going via that route of selecting specific K's then there will be two cases - check for n to be even or odd. Because, as it is said in the question, in each round, the girl prepares two copies of the same dish, so if n is even, you could easily distribute the dish pairs to each of the judges. However, if the number of judges(n) is odd, then you will have to specially take care of dividing dish pairs to different judges. Although it is not impossible via this route, you have to handle for both even and odd cases.


answered 19 Jun '17, 01:48

utkalsinha's gravatar image

accept rate: 12%

Selecting k=2 every time will only work for even number of judges. You'll have to do something more for odd n.


answered 19 Jun '17, 01:30

hikarico's gravatar image

accept rate: 28%

2 2 1 1 2 2 1 2 2 1 1 2 2 1 2 this will be the answer every time i put k=2 where is the problem please point out specifically.

The rule of the contest is each judge (ie 2 here) must have tasted each dish (ie 2 dishes) exaclty twice which is happening here.How does n matters?

Thanks for replying


answered 19 Jun '17, 01:36

sarthak_1995's gravatar image

accept rate: 0%

You wrote the answer for n=2, that is correct... Put n=3 and take a review to the answer, does it hold the condition yet?


answered 19 Jun '17, 01:40

dfonnegrag's gravatar image

accept rate: 25%

i think i am confused with the conditions could any1 please clarify it for me what exactly need to be done.

Thanks in advance :)


answered 19 Jun '17, 01:44

sarthak_1995's gravatar image

accept rate: 0%

I spent a significant amount of time trying to understand this question.

The key phrases are wrapped in asterisks:

We will choose **k distinct recipes** and Ada will prepare **two identical dishes for each of them**.

You can arbitrarily decide the number of rounds and the number of invited judges in each round, but as a rule of the contest at the end of all rounds **each judge must have tasted every recipe exactly twice**.

Basically, you're given a fix amount of judges from the input. Each of the judge must have tasted every recipe exactly twice, and Ada will prepare 2 dishes for each recipe she prepared. Every round, all the judges will taste exactly 2 dishes. Therefore, the amount of round is determined by the number of judges given by the input. If there are 4 judges, 4 rounds is needed to allow a total of 8 sampling of the dishes (2 dishes each recipe, 4 rounds X 2 dishes = 8 dishes).

You can look at my code here for better understanding: my python3 answer


answered 19 Jun '17, 09:26

archuman's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 19 Jun '17, 01:28

question was seen: 336 times

last updated: 19 Jun '17, 09:26