rohantrix's blog

By rohantrix, history, 3 years ago, In English

In today's Codeforces Round (#763) problem B, I tried finding a pair object in a HashSet. Even after overriding equals() and hashcode() methods, I still ended up with WA on test 4. Here is the link to my solutions:

1) WA Submission using HashSet

2) Working Solution using 2D matrix

Please let me know of a good fix for this.

vinam SecondThread

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 3   Vote: I like it +15 Vote: I do not like it

Use Integer.equals instead of == in your pair.equals, otherwise you get false when comparing two objects with the same value but different references. Btw, same bug in the pair.compareTo method.

Check this AC solution: https://mirror.codeforces.com/contest/1623/submission/140959789