FastPrepSame Binary Tree

Same Binary Tree

Odoo logoOdoo● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Two binary trees are serialized in level order. Each node value is a string and # marks a missing child. Trailing missing-child markers may be omitted.

Return whether the two serializations describe identical structure and equal values.

Function

isSameTree(firstLevelOrder: String[], secondLevelOrder: String[]) → boolean

Examples

Example 1

firstLevelOrder = ["1","2","3"]secondLevelOrder = ["1","2","3"]return = true

Case 1 exercises the documented deterministic contract.

Example 2

firstLevelOrder = ["1","2"]secondLevelOrder = ["1","#","2"]return = false

Case 2 exercises the documented deterministic contract.

Example 3

firstLevelOrder = []secondLevelOrder = []return = true

Case 3 exercises the documented deterministic contract.

Constraints

  • 0 <= firstLevelOrder.length, secondLevelOrder.length <= 200000.
  • Node values never equal #.
  • Each serialization is structurally valid.

More Odoo problems

See Odoo hiring insights
public boolean isSameTree(String[] firstLevelOrder, String[] secondLevelOrder) {
    // Write your code here.
}
firstLevelOrder["1","2","3"]
secondLevelOrder["1","2","3"]
expectedtrue
Checking account…