SHARECHAT Hiring On-Campus OA (2021) | Problem Longest ZigZag Path in a Binary Tree

Question · Posted Jun 2026

Problem Statement You are given the root of a binary tree. A ZigZag path starts at any node and alternates between moving to the left child and the right child at each step. For example: Left → Right → Left → Right Right → Left → Right → Left The length of a ZigZag path is defined as the number of edges traversed, not the number of nodes visited. Your task is to find the length of the longest ZigZag ...

The full answer & interview discussion are available to premium members.

Log in Create a free account