nikunjsoni

1237

May 17th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. /*
  2.  * // This is the custom function interface.
  3.  * // You should not implement it, or speculate about its implementation
  4.  * class CustomFunction {
  5.  * public:
  6.  *     // Returns f(x, y) for any given positive integers x and y.
  7.  *     // Note that f(x, y) is increasing with respect to both x and y.
  8.  *     // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
  9.  *     int f(int x, int y);
  10.  * };
  11.  */
  12.  
  13. class Solution {
  14. public:
  15.     vector<vector<int>> findSolution(CustomFunction& customfunction, int z) {
  16.         vector<vector<int>> ans;
  17.         int x=1000, y=1;
  18.         while(x>=1 && y<=1000){
  19.             int val = customfunction.f(x, y);
  20.             if(val > z)
  21.                 x--;
  22.             else if(val < z)
  23.                 y++;
  24.             else{
  25.                 ans.push_back({x,y});
  26.                 x--; y++;
  27.             }
  28.         }
  29.         return ans;
  30.     }
  31. };
Advertisement
Add Comment
Please, Sign In to add comment