← Back
00:00

Asset Tree Size

Datadog interview questions · Medium · Coding round · 6 tests

The input is a forest of one or more asset trees, and each node carries a name. Leaves stand for files and hold a numeric size, while internal nodes stand for directories that have children.

You also receive an absolute path whose segments are separated by slashes. Locate the node that path points to and add up the sizes of every leaf in its subtree; if that node is itself a leaf, the answer is simply its own size.

Interface

interface AssetNode {
  name: string;
  size?: number;
  children?: AssetNode[];
}

calculateAssetTreeSize(
  roots: AssetNode[],
  targetPath: string,
): number | null
Idle