πŸ“ Problem Details

πŸ’­What Were My Initial Thoughts?

- we need to find the permutation of x and y that results in the output z when passed into function func
- the constraints of the question allow for a less optimal approach 

πŸ€”What Did I Struggle With?

~ wording of the question wasnt the best and took some time to comprehend 

πŸ’‘ Explanation of Solution

- have a 2d results vector
- nested for loop with iterators x and y, with upper limits of 1000
- pass x and y into the customfunction, pushing the vector {x,y} into result if if returns z
- return the results vector

βŒ› Complexity Analysis

Time Complexity: O(1)
- at first glance, the approach could be seen as O(n^2) due to the nested for loop, but since we know the upper bound being limited to 1000, the time complexity is constant

Space Complexity: O(n) where n is the number of permutations of x and y 

πŸ’» Implementation of Solution

 
class Solution {
public:
    vector<vector<int>> findSolution(CustomFunction& customfunction, int z) {
        vector<vector<int>> result;
 
        for (int x = 1; x <= 1000; ++x) {
            for (int y = 1; y <= 1000; ++y) {
                if (customfunction.f(x, y) == z) {
                    result.push_back({x,y});
                }
            }
        }
        return result;
    }
};