If you're seeing this message, it means we're having trouble loading external resources on our website. Show If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked. View Discussion Improve Article Save Article View Discussion Improve Article Save Article Given coordinates of bottom-left and top-right corners of a rectangle. Check if a point (x, y) lies inside this rectangle or not. Examples:
This problem is already discussed in a previous post. In this post, we have discussed a new approach. Approach: If we observe carefully, It will be clear that for a point to be lie inside the rectangle, it should be lie inside the x-coordinate (x1, x2) of the rectangle as well as it should also lie inside the y-coordinate (y1, y2) of the rectangle. Algorithm:
Below is the implementation of the above approach: C++
C
Java
Python3
C#
PHP
Javascript
Time Complexity: O(1) Which point is lie on yThe abscissa of any point lying on the y-axis is 0. So the point lying on the y-axis is (0, 3).
Where will the point 0 3 lie?Assertion (A) : The point (0,-3) lies on the y-axis.
On which axis does the point 0.5 lie?(a) The point (−5, 0) lies on x-axis.
Which point does not lie in yhere, points (2,0) and (5,0) lie on the X-axis and point (0,5) lies on Y-axis. hence, the only point which does not lie on the axis is (3,4). hope this helps.
|