Help me in solving TRICOIN problem

My issue

I use one data structure called binary tree but it shows total heigth
how to approach each node

My code

#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;
}

Problem Link: Coins And Triangle Practice Coding Problem - CodeChef

type or paste code here#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;
}
can you tri coins wil be solved with binary search tree

@saideepakpatib
your logic will give to tle .
just refer the following code for better understanding of the logic

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int count=0;
        for(int i=1;i>0;i++){
            n=n-i;
            if(n<0) {
                break;
            }
            count++;
        }
        printf("%d\n",count);
    }
	
	return 0;
}