-
Notifications
You must be signed in to change notification settings - Fork 161
/
find-positive-integer-solution-for-a-given-equation.md
48 lines (36 loc) · 1.75 KB
/
find-positive-integer-solution-for-a-given-equation.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<p>Given a function <code>f(x, y)</code> and a value <code>z</code>, return all positive integer pairs <code>x</code> and <code>y</code> where <code>f(x,y) == z</code>.</p>
<p>The function is constantly increasing, i.e.:</p>
<ul>
<li><code>f(x, y) < f(x + 1, y)</code></li>
<li><code>f(x, y) < f(x, y + 1)</code></li>
</ul>
<p>The function interface is defined like this: </p>
<pre>
interface CustomFunction {
public:
// Returns positive integer f(x, y) for any given positive integer x and y.
int f(int x, int y);
};
</pre>
<p>For custom testing purposes you're given an integer <code>function_id</code> and a target <code>z</code> as input, where <code>function_id</code> represent one function from an secret internal list, on the examples you'll know only two functions from the list. </p>
<p>You may return the solutions in any order.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> function_id = 1, z = 5
<strong>Output:</strong> [[1,4],[2,3],[3,2],[4,1]]
<strong>Explanation:</strong> function_id = 1 means that f(x, y) = x + y</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> function_id = 2, z = 5
<strong>Output:</strong> [[1,5],[5,1]]
<strong>Explanation:</strong> function_id = 2 means that f(x, y) = x * y
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= function_id <= 9</code></li>
<li><code>1 <= z <= 100</code></li>
<li>It's guaranteed that the solutions of <code>f(x, y) == z</code> will be on the range <code>1 <= x, y <= 1000</code></li>
<li>It's also guaranteed that <code>f(x, y)</code> will fit in 32 bit signed integer if <code>1 <= x, y <= 1000</code></li>
</ul>