I'm doing a practice coding test problem and I have no idea how to solve this...

I'm doing a practice coding test problem and I have no idea how to solve this. Am I just retarded or is this supposed to be very difficult?

Attached: Screen Shot 2022-06-13 at 1.23.08 AM.png (882x1334, 183.58K)

what's difficult about it? It's fairly trivial. Go through the array in segments of size 1, 2, 4, 8, etc. Then count the value of each node towards the side they are on. For example

3 -> it's root, ignore
[6, 2] -> add 6 to left, 2 to right
[9, -1, 10, -1] -> add 9 to left, 10 to right

and so on. In the end you have a sum for left and a sum for right. Compare and print an answer.

You just traverse the branches and compare the sizes? How is it hard?

all you gotta do is run a pre-order on that tree, add values until you get back to the root, save that value, then do the same for the other side

Couldn't you start at [1], split the arrays into two more arrays (left and right) based upon every other one (off even index after [0], and then subtract left from right. If you have a positive number, or a negative number would tell you left or right

The absolute state of code bootcampers

you have to learn it, unironically. Despite what CStards claim it's not an IQ test, they all just grind hundreds of questions and more or less memorize the approaches. It's like how the chinese learn math, just constant practice

I don't understand how it even makes sense for a binary tree to be represented as an array or how you're supposed to traverse it. I've spent an hour trying to make sense of it and I don't see it.

Go from root node thru children R->L then the nodes of those children R->L

Does "larger" here mean "more nodes" or does it mean "the sum of the values in the nodes is larger"?

Are nodes guaranteed to have values >=0? If not, how do I distinguish a node with value "-1' from an empty node?

Question sucks.

What I don't understand is how you even know what position in the array is what depth in the tree, since you can have an arbitrary number of nodes at each depth. How does it makes any sense to represent this kind of data structure as an array?

It's represented as an array in chunks. First element in the array is the root. Next two elements are the first layer of the tree. Next four elements are the second layer of the tree, etc.

This is your brain on web dev.

It means the sum is larger because in the example they gave, the output is Left.

Yeah its pretty dumb man

It's a terrible representation of the data structure, but it makes sense.

Assume we count from 1. Array value 1 is the root. Array values 2 and 3 are the next branch down, left to right. Array values 4 through 7 are the next branch down, left to right. Array values 8 through 15 are the next branch down, left to right.

Within each chunk, the "left" half of the tree is the first half of the values; the "right" half of the tree is the right half of the values.

Go through each chunk, cut it in half, add up the halves, repeat until done. Then compare the sums. Be sure to ignore the -1's.

Well this was a coding test categorized under "frontend", which makes no sense because I've been a frontend dev for years and I've never had to do anything even remotely like this in my day to day work.

So if there's no node it's always going to be represented as a -1? The question doesn't make that clear at all because in the example it just ends at 10 instead of -1 for the missing node after it.

Leetcode? Shitty pajeet platform where everyone copy pastes shared submissions.

yeah that's the confusing part. The last item in the array should be -1. I guess we can assume that if the last layer abruptly ends, the rest of it is all -1s.

No this is on hired.com

>Despite what CStards claim it's not an IQ test, they all just grind hundreds of questions and more or less memorize the approaches
that's how iq tests work too, so it kind of is one.

Spend your shekels elsewhere if a introductory problem is this gay