Skip to content

Practice Find Positive Integer Solution for a Given Equation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1237
LeetCode Problem

Find Positive Integer Solution for a Given Equation

Problem Statement

Given a CustomFunction object with method int f(int x, int y) and a target z, return all positive integer pairs [x, y] for which f(x, y) equals z. The hidden function is strictly increasing in each argument separately: increasing x while fixing y increases its result, and increasing y while fixing x also increases its result. You may query f; its formula is not provided. Return the pairs in any order. The judge selects one of nine hidden implementations using function_id, supplies the callable object to findSolution, and compares the returned pairs with its answer key.

Source: Find Positive Integer Solution for a Given Equation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
function_id = 1, z = 5
Output
[[1,4],[2,3],[3,2],[4,1]]

# Example 2

Input
function_id = 2, z = 5
Output
[[1,5],[5,1]]

Constraints

1 <= function_id <= 9
1 <= z <= 100
It is guaranteed that the solutions of f(x, y) == z will be in the range 1 <= x, y <= 1000.
It is also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000.

Related LeetCode Problems

Practice more problems similar to Find Positive Integer Solution for a Given Equation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.