2dbi
Home/Zapier/Nested List Weight Sum
ZZapier·DSAEngineerTechnical Phone Screen

Nested List Weight Sum

Problem

Given a nested list of integers, return the sum where each integer is weighted by its depth.

Example

[[1,1],2,[1,1]] -> 1*2+1*2+2*1+1*2+1*2 = 10

Constraints

  • Arbitrary nesting

Approach

DFS/BFS tracking depth. Reported Zapier question; II variant weights by inverse depth.

added 6 days ago
LeadersAccount