Vivek and Party Problem

only 1st test cases fail any one figure out.
what case i’m missing.

@Saurabh-Kumar-1331476656958199
please figure out my mistake
i am stick to this question last 1 week.

For this test case your code did not print A in the order of drinking.
5
A
B
C
D
E
5
C A
D A
B D
E B
E C

@Robin_rst i resolved this issue. but still it throwing 1st test case fail.

code link is below

I think you have sent the same code. Your code still not printing A.
For this example output should be -:
5
A
B
C
D
E
5
C A
D A
B D
E B
E C

Output -: E B C D A

@Robin_rst exactly is pasted the same code.
for above input my code is printing
following output
E C B D A

Correct Output is E B C D A.
Because B comes before C in the input and there is no relation between B and C.

Try to understand the logic.
3
v
w
b
2
w v
b
same sequence of given input(v, w, b)
v–>
w—>
b—>

Given relation:
w v
drink w before v. So, v depends on w.
So, v—>w,

b w
drink b before w. So, w depends on b.
So, w—>b.

Now, the structure is:
v—>w,
w—>b
b—>

Now, check top to bottom which has zero dependency.
b has zero dependency. First drink b.
Now, delete b from structure because he already drunk the b.
And erase b from all elements which depends on b.
1st output is b.
Then, structure looks like below.
v—>w.
w—>

Again check top to bottom which has zero dependency. Now, find w.
Then he drink w.
Now, delete w from structure because he already drunk the w.
And erase w from all elements which depends on w.
2nd output is w.
Then, structure looks like below.
v—>

Again check top to bottom which has zero dependency. Now, find v.
Then he drink v.
Now, delete v from structure because he already drunk the v.
And erase v from all elements which depends on v.
3rd output is v.
Then, structure looks like below.
The structure is empty. end of loop.
So, the output is b w v.

1 Like

awesome explanation.

Please do rate me. I am closing thread, i hope you understood every part.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

@Robin_rst @rajujnvgupta can anyone of you please send me tha exact solution to this problem like in total codes I’m not getting ur solution correctly

@Robin_rst bro can you solve this ??
https://hack.codingblocks.com/app/dcb/938
Today’s dcb ?
I’m getting problem in Test case -1 and
Test case 0 & 2 are passed