Find X and Y in Linear Equation
Basic Accuracy: 30.07% Submissions: 153 Points: 1

Given A, B and N. Find x and y that satisfies equation Ax + By = N. If there's no solution print -1 in place of both x and y.
Note: There are Multiple solutions possible. Find the solution where x is minimum. x and y should both be non-negative.


Example 1:

A = 2, B = 3, N = 7
2 1
2*2 + 3*1 = 7.

Example 2:

A = 4, B = 2, N = 7
-1 -1
There's no solution for x and y the equation.


Your Task:
You don't need to read input or print anything. Your task is to complete the function findXandY() which takes 3 Integers A,B and N as input and returns a list of 2 integers with the first integer x and the second being y.


Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)


1 <= A,B <= 105
0 <= N <= 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Find X and Y in Linear Equation

Output Window