(arrayOne, arrayTwo)
| 1 | // time O(n^2) |
| 2 | // space O(n^2) |
| 3 | function sameBsts(arrayOne, arrayTwo) { |
| 4 | if (arrayOne.length !== arrayTwo.length) return false; |
| 5 | if (arrayOne.length === 0 && arrayTwo.length === 0) return true; |
| 6 | if (arrayOne[0] !== arrayTwo[0]) return false; |
| 7 | |
| 8 | // create 4 arrays O(n) time and do this n time which leads to n^2 |
| 9 | const leftOne = getSmaller(arrayOne); |
| 10 | const leftTwo = getSmaller(arrayTwo); |
| 11 | const rightOne = getBiggerOrEqual(arrayOne); |
| 12 | const rightTwo = getBiggerOrEqual(arrayTwo); |
| 13 | |
| 14 | return sameBsts(leftOne, leftTwo) && sameBsts(rightOne, rightTwo); |
| 15 | } |
| 16 | |
| 17 | function getSmaller(array) { |
| 18 | const smaller = []; |
nothing calls this directly
no test coverage detected