|
| 1 | +package com.fishercoder.solutions; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +/** |
| 6 | + * 1237. Find Positive Integer Solution for a Given Equation |
| 7 | + * |
| 8 | + * Given a function f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z. |
| 9 | + * The function is constantly increasing, i.e.: |
| 10 | + * |
| 11 | + * f(x, y) < f(x + 1, y) |
| 12 | + * f(x, y) < f(x, y + 1) |
| 13 | + * The function interface is defined like this: |
| 14 | + * |
| 15 | + * interface CustomFunction { |
| 16 | + * public: |
| 17 | + * // Returns positive integer f(x, y) for any given positive integer x and y. |
| 18 | + * int f(int x, int y); |
| 19 | + * }; |
| 20 | + * For custom testing purposes you're given an integer function_id and a target z as input, |
| 21 | + * where function_id represent one function from an secret internal list, on the examples you'll know only two functions from the list. |
| 22 | + * You may return the solutions in any order. |
| 23 | + * |
| 24 | + * Example 1: |
| 25 | + * Input: function_id = 1, z = 5 |
| 26 | + * Output: [[1,4],[2,3],[3,2],[4,1]] |
| 27 | + * Explanation: function_id = 1 means that f(x, y) = x + y |
| 28 | + * |
| 29 | + * Example 2: |
| 30 | + * Input: function_id = 2, z = 5 |
| 31 | + * Output: [[1,5],[5,1]] |
| 32 | + * Explanation: function_id = 2 means that f(x, y) = x * y |
| 33 | + * |
| 34 | + * Constraints: |
| 35 | + * 1 <= function_id <= 9 |
| 36 | + * 1 <= z <= 100 |
| 37 | + * It's guaranteed that the solutions of f(x, y) == z will be on the range 1 <= x, y <= 1000 |
| 38 | + * It's also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000 |
| 39 | + */ |
| 40 | +public class _1237 { |
| 41 | + |
| 42 | + // This is the custom function interface. |
| 43 | + // You should not implement it, or speculate about its implementation |
| 44 | + interface CustomFunction { |
| 45 | + // Returns f(x, y) for any given positive integers x and y. |
| 46 | + // Note that f(x, y) is increasing with respect to both x and y. |
| 47 | + // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1) |
| 48 | + public int f(int x, int y); |
| 49 | + } |
| 50 | + |
| 51 | + public static class Solution1 { |
| 52 | + public List<List<Integer>> findSolution(CustomFunction customfunction, int z) { |
| 53 | + return null; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments