Given A set of Rectangle that are parallel to the X axis. We should find the most small set of lines that are parallel to the Y axis. such that each Rectangle will be crossed by at list one line. For example : Given a set of 4 Rectangle.
the output will be X = 3 and X = 7.
I was thinking about a greedy algorithm which pass vertical lines to the X axis and If it is crossed with the most number of Rectangles it will enter the line into the group.

Try your greedy algorithm on this example:
Using the notation $(a,b)$ for a rectangle whose vertices have $x$-coordinates $a$ or $b,$ consider a set of six rectangles, $(0,2),$ $(0,6),$ $(0,7),$ $(3,10),$ $(4,10),$ and $(8,10).$
The greatest number of rectangles you can intersect with the first line is four, with a line between $x=4$ and $x=6.$ You then require two more lines to intersect the remaining rectangles. But the entire set can be done with just two lines.
In this example, the "greatest number of rectangles" algorithm fails because it picks a line in the middle of the figure, leaving some uncrossed rectangles on the left and some uncrossed rectangles on the right, requiring (too many) additional lines on both the left and right. You might consider trying to find the leftmost line of your minimal set of lines instead. (By symmetry, if that works, you can just as easily find the rightmost line instead.)