Skip to content
Advertisement

Tag: algorithm

Search Insert Position-Wrong answe

I’m solving a problem (leetcode 35). My code was accepted in run code result but when I submit it returns wrong answer.I don’t really understand what is wrong in my answer . Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were

how to sort recursively in JS

I’m trying to sort an Array type data recursively. Here’s the data structure. I wanna sort by either ‘id’ or ‘name’. This is what I tried. In my poor logic, it seems working but not properly working. Because item’s children or children’s children is not sorted. 🙁 What should I fix? or maybe my approach was totally wrong? Thank you

Finding highest parent in a tree structure

I have a tree structure that is made out of the data below. I need a search algorithm to find the top leader when I put in anyone’s _id value, regardless of leader or child. For example, if the input is “615e8215c3055d1addc216b0” (the id of Rahman) or “61164b4bc08f86505e7dcdd8” (the id of Aaron Aziz) it should return the id of “Aaron

Advertisement