Skip to content

Commit

Permalink
Create 31.03.2024.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Masked-coder11 authored Mar 30, 2024
1 parent d255d5e commit a4f20d9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 31.03.2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
int ans=INT_MIN;

void solve(Node* root, int n){
if(root==NULL) return;

if(root->key <= n){
ans=max(ans, root->key);
solve(root->right, n);
}
else{
solve(root->left, n);
}

return;
}
int findMaxForN(Node* root, int n) {
// code here
solve(root, n);
if(ans==INT_MIN){
ans=-1;
}

return ans;

}
};

0 comments on commit a4f20d9

Please sign in to comment.