Pure Storage Interview Question - Need help

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2020-03-03Added By Anonymous
Source: Link
Company: Pure Storage
Role: unknown
Interview Stage: Onsite
Location: unknown
Year: unknown

Guys - Could you please help me to understand and solve following question. Preparing for Pure Storage Onsite interview and found this question is frequently asked -

https://repl.it/@koosham/Buddy-Bitmap this link has the solution but I could not understand it.

Thanks in advance.

----
Given a complete binary tree with nodes of values of either 1 or 0, the following rules always hold:
(1) a node's value is 1 if and only if all its subtree nodes' values are 1
(2) a leaf node can have value either 1 or 0
Implement the following 2 APIs:
set_bit(offset, length), set the bits at range from offset to offset+length-1
clear_bit(offset, length), clear the bits at range from offset to offset+length-1

i.e. The tree is like:
0
/ \
0 1
/ \ / \
1 0 1 1
/\ / \ /
1 1 1 0 1
Since it's complete binary tree, the nodes can be stored in an array:
[0,0,1,1,0,1,1,1,1,1,0,1]
Comments