shlogg · Early preview
Md Ariful Haque @mah-shamim

Linked List In Binary Tree: Checking For Subpaths With DFS

Recursive DFS checks if linked list matches binary tree path, returning true for matching paths and false otherwise.

1367. Linked List in Binary Tree
Difficulty: Medium
Topics: Linked List, Tree, Depth-First Search, Breadth-First Search, Binary Tree
Given a binary tree root and a linked list with head as the first node.
Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise return False.
In this context downward path means a path that starts at some node and goes downwards.
Example 1:


Input: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
Output: true
Explanation: Nodes in blue form a...