My issue
My code
#include <iostream>
using namespace std;
int main() {
int i,t;
cin>>t;
for(i=0;i<t;i++)
{
int n,j,k=0;
cin>>n;
while(n>1)
{
n=n-k;
k++;
}
std::cout << k << std::endl;
}
return 0;
}
Problem Link: TRICOIN Problem - CodeChef
can you retify my problem i find heigth of my node how to known that heigth of each node
include <stdio.h>
include <stdlib.h>
struct node {
int data;
struct node* left;
struct node* right;
};
struct node* createNode(int data) {
struct node* newnode = malloc(sizeof(struct node));
newnode->data = data;
newnode->left = NULL;
newnode->right = NULL;
return newnode;
}
struct node* insert(struct node* root, int data) {
if (root == NULL) {
return createNode(data);
}
if (root->data > data) {
root->right = insert(root->right, data);
} else {
root->left = insert(root->left, data);
}
return root;
}
int height(struct node* root) {
if (root == NULL) {
return 0;
}
int right = height(root->right);
int left = height(root->left);
if (right > left) {
return right + 1;
} else {
return left + 1;
}
}
int main() {
struct node* root = NULL;
int n, data;
scanf(ā%dā, &n);
while (n--) {
scanf("%d", &data);
root = insert(root, data);
}
int k = height(root);
printf("%d", k);
return 0;
}