Flatten nested list
You are given a nested list of integers where each element is either an integer or a (possibly empty) list whose elements are also integers or nested lists. Flatten it and return the integers in the order a depth-first iterator would yield them. Implement it without using recursion at flatten time — simulate the traversal with an explicit stack. The total number of integers is at most 10000 and nesting depth is at most 100. Encode lists as Python lists and integers as Python ints in the input.
Implement
flatten_nested(nested: list) → list[int]Examples
in
[[1,[4,[6]]]]out[1,4,6]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[1,[4,[6]]]][1,4,6]not run yetsample