Online C++ Compiler

#include<bits/stdc++.h> using namespace std; struct Node { int data; struct Node* left, *right; }; struct Node* newnode(int data) { struct Node* node = new Node; node->data = data; node->left = node->right = NULL; return (node); } bool findSumUntill(Node *node, unordered_set<int> &hashTable, int rootVal) { if (node == NULL) return false; int otherVal = rootVal - node->data; if (hashTable.find(otherVal) != hashTable.end()) return true; hashTable.insert(node->data); bool isFound = findSumUntill(node->left, hashTable, rootVal) || findSumUntill(node->right, hashTable, rootVal); hashTable.erase(node->data); return isFound; } bool findPairSum(Node *root) { unordered_set<int> hashTable; return findSumUntill(root->left, hashTable, root->data) || findSumUntill(root->right, hashTable, root->data); } int main() { struct Node *root = newnode(7); root->left = newnode(2); root->right = newnode(3); root->left->left = newnode(5); root->left->right = newnode(9); root->left->left->left = newnode(1); root->left->left->right = newnode(6); root->right->left = newnode(8); if(findPairSum(root)) cout<<"Pair with sum equal to root value found"; else cout<<"No pairs found"; return 0; }