Time/Space complexity tree creation from traversal data


Could someone please tell me what time and space complexity my code has?
This is the exercise 9.11 ‘Reconstruct a binary tree from traversal data’
The authors propose a solution where they save the indices of the nodes in a hash table. I search for the index in an array that is getting smaller with every recursive call. My test cases are approximately ~300us slower. But I feel like that if it is O(n²) it should be way slower.

Thank you.