So I have an API which returns me the value of water dispensed for the last 7 days and it can contain an empty array or a value such as: Assuming today is Thursday and I need an array of objects which would fill missing last 7 days data as: How would you do this considering that you need to
Tag: algorithm
How to support 256 values without null in array-tree pattern generator?
I love this answer to that question, it’s so creative and robust. I translated it to support 256 values without supporting null arrays, and the tree/array shape generation seems to work. However, I am stuck on how the encoding radix-like function works, and how to translate that given that now POSSIBLE_SHAPE_LIST is only 9 elements instead of 16 now. How
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
Why do I get different answer when using `++` vs using `+1` [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 1 year ago. Improve this question
How to sort two sorted arrays without using sort methods (sort) nor sort algorithms (bubble sort, quick sort)
I was asked in an interview and my answer was similar to this, which is wrong due to the final loop. Answer What you are talking about — “sorting” two arrays that are each themselves already sorted — is called a merge. This is how you do that:
Time Space Complexity of k smallest of unsorted array
I solved this problem given to me in an interview, but I do not know what the Time Space complexity is. What is the Time Space complexity of the following solution? I think it might be O(log(n)) or is it simple O(n)? Answer Your solution uses a characteristic of JavaScript objects: keys that are decimal representations of indexes will be
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
How can I find remaining percentages if one or two percentages are known
Consider the following Objects: They represent a percentage, i.e. the sum of all three grades will be exactly 100. How can we interpolate the keys with ‘No-Data’ whenever their values can be calculated? Expected Results: My solution in pseudo-code: There are two main questions here: How do I find out how many and which keys are ‘No-Data’. Can I rearrange
AVL Tree implementation: Insert function – Reference get twisted
I got the bug when adding 13 to the tree, the left and right pointer of node 10 have reference back to the root, and create cycle reference. I think it’s because I understand Javascript syntax wrong. code (open the console) Any suggestion? Answer The problem is that you don’t use the returned node reference from the recursive call of