Flatten nested list

Write codeMedium25 minMeta style

Your task

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.

Examples

flatten_nested(nested: list) -> list[int]
Example 1
Inputflatten_nested([1, [4, [6]]])
Output[1, 4, 6]