- The first four lines are dominated by
getChildren(currentValue.input). If the length ofcurrentValue.input- the length of the children - is proportional to n, then it has a runtime complexity of O(n ²). - Then it calls
getValueForLevel(children.left, k-1). It is easy to construct inputs which maximize the length ofchildren.leftsuch as"4(3(2(1))))"without right children. For this input, in each iteration, the length ofchildren.leftis reduced by 3. - The final call to
JSON.parseis in O(n)is in O(n).