Formatted with GPT.
Total 4 questions, 2 dsa + 1 sql + 1 data frame coding(only py allowed)
You are given N cookies, each having a specific weight. The cookies must be packed into a nested box structure following a specific rule.
Each box consists of three portions:
The cookies must be arranged such that:
This effectively forms a recursive nested structure similar to a tree.
Construct the packing structure.
Represent the structure using bracket notation:
[left [center] right]Given a target cookie weight, determine the box level (depth) at which it is placed:
NN integers representing weightstarget (weight to search)Input
N = 5
weights = [76, 62, 99, 21, 39]
target = 99Output
Structure: [76[62[21]39]99]
Box level of 99: 3You are given a list of integers. Each integer represents a number encoded in a special format.
For a number x:
x represents k, the number of digits to be used as the exponent.Let:
base = first (len(x) - k digits)exponent = last k digitsThen:
f(x) = base ^ exponentCompute the sum of f(x) for all numbers in the list.
Input
[4122, 2021]Explanation
Output
4^12 + 20^2 = 16777216 + 400 = 16777616