UNICOURS Hashing approach not working

Link : https://www.codechef.com/MAY17/problems/UNICOURS/

MY Sol : http://ideone.com/BGnFLx

Although i have solved this problem but just want to know why my hashing approach is not working???

hey , i think you are considering A[i] as course (id), but it’s number of courses that are prerequisite courses for i-th course.

example : if A[i] = 5

by hashing it should be (hash[0 to i-1]++) not hash[A[i]]++
It may give TLE so there is easy approach : here

2 Likes

It fails in this testcase:

1
4
0 1 1 3
Your code outputs 2. But answer is 1.

1 Like

I just came up with a easy solution than hashing…
Here is my solution:

https://www.codechef.com/viewsolution/13471671

:slight_smile:

it’s a simple finding maximum element of an array problem i guess

Ok Got my mistake!!!
thanks!!

Ya got it .Thanks btw.