We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Checking if the points lies inside a square can be done without any floating point operations. Two hints (References almost contain the solution to this problem. Do not open them if you still want to figure your own way out just by using the hints) :
You can calculate the other veticies of the squre using the two diagonal points given using some maniputaion of vectors. The only factor of division by 2 can be taken to the other side of the inequalities while comparison, to avoid division. Reference
The actual condition for checking if point is inside the squre can be either done by the method of comparing the sum of areas or even better the dot product of edges of squre and the vector from vertex to point.Reference
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
A Circle and a Square
You are viewing a single comment's thread. Return to all comments →
Checking if the points lies inside a square can be done without any floating point operations. Two hints (References almost contain the solution to this problem. Do not open them if you still want to figure your own way out just by using the hints) :