Skip to content

Instantly share code, notes, and snippets.

@mgiacomini
Last active August 29, 2015 14:04
Show Gist options
  • Save mgiacomini/387af420f68793b136ff to your computer and use it in GitHub Desktop.
Save mgiacomini/387af420f68793b136ff to your computer and use it in GitHub Desktop.
typedef struct node {
int key;
struct node *left;
struct node *right;
} node;
int is_odd(node *n){
// verify the root key
if (n->key % 2 != 0)
return 1;
return 0;
}
int find_path_with_max_odd_keys(node *root){
int keys, left_keys, right_keys = 0;
if(is_odd(root) == 1)
keys++;
left_keys = find_path_with_max_odd_keys(root->left);
right_keys = find_path_with_max_odd_keys(root->right);
if(left_keys >= right_keys)
return keys + left_keys;
return keys + right_keys;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment