sahilrathore03's blog

By sahilrathore03, 18 hours ago, In English

I was trying to solve this problem during contest.
Problem: 2061B - Kevin and Geometry

I wrote this solution for it which is an O(nlogn) solution but it is giving tle on the last pretest(10). I am unable to figure out the reason for this.
Submission: 302117530

Approach:
- Check the frequency of every element using map.
- If all elements are distinct, no valid solution is possible.
- If there is an element with frequency >=4 we can simply print that element 4 times since we found a square.
- If more than 1 elements have frequency greater than 1 we can print those 2 elements twice since we found a rectangle.
- Now only 1 case remains. We have a single element with freq>1 and we fix the isosceles side as this element. Now for the base and roof we can select any two elements such that | base — roof | < 2*side. For this we sort the array in O(nlogn) time and check adjacent elements.

TC: O(nlogn).
SC: O(n)

Can anyone help me out. Where is the problem with this solution?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it