Verify if Y could be made a number of of X by including any worth to each


View Dialogue

Enhance Article

Save Article

Like Article

View Dialogue

Enhance Article

Save Article

Like Article

Given two numbers X and Y (X ≤ Y), you possibly can choose any constructive integer Z and add them to each X and Y. The duty is to seek out whether or not it’s attainable to make X a a number of of Y.


Enter: X = 7, Y = 15
Output: Sure

Clarification: We will select Z = 1 and add them to 7 and 15. Thus, 7 + 1 = 8 is an element of 15 + 1 = 16.

Enter: X = 9, Y = 10

Output: No

Strategy: The issue could be solved primarily based on the next thought:

  • First, if X = Y, then the reply is clearly “Sure”.
  • In any other case, notice that regardless of which Z we select, the distinction between X and Y stays fixed.
    Let d = Y – X. A legitimate Z exists if and provided that X ≤ d.

Comply with the steps talked about under to implement the above thought:

  • First, we discover the distinction between X and Y let d = Y – X.
  • If d = 0 or X ≤ d, then print “Sure”
  • Else print “No”

Beneath is the implementation of the above method.




import java.util.*;


class GFG {




    public static void verify(int X, int Y)

     X <= d)







    public static void predominant(String[] args)


        int X = 7;

        int Y = 15;



        verify(X, Y);



Time Complexity: O(1) 
Auxiliary House: O(1)


Leave a Reply

Your email address will not be published. Required fields are marked *