Skip to content

Harshbhagat22/LeetCode-Trees-Series

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌳 LeetCode Trees Series (Java Solutions)

This repository contains Java solutions for tree-based problems from LeetCode. It is designed for coding interview preparation and to help developers strengthen their Tree and Binary Search Tree (BST) knowledge.


πŸ“Œ Topics Covered

  • Binary Tree Basics

    • Traversals (Preorder, Inorder, Postorder, Level-order)
    • Maximum Depth / Minimum Depth
    • Diameter of Binary Tree
    • Path Sum Problems
  • Binary Search Trees (BST)

    • Insertion, Deletion, Search
    • Validate BST
    • Lowest Common Ancestor
    • Convert Sorted Array to BST
  • Advanced Tree Problems

    • Serialize & Deserialize Binary Tree
    • Construct Tree from Traversals
    • Flatten Binary Tree to Linked List
    • Binary Tree Cameras
    • Recover BST
  • Special Trees

    • N-ary Trees
    • Trie (Prefix Tree)
    • Segment Tree
    • Fenwick Tree (Binary Indexed Tree)

πŸ› οΈ How to Run

  1. Clone the repo

    git clone https://github.com/<your-username>/LeetCode_Trees_Series.git
    cd LeetCode_Trees_Series
  2. Compile and run Java files

    javac Solution.java
    java Solution
  3. Each problem is stored in a separate folder with the following format:

    <problem_number>_<problem_name>/
        β”œβ”€β”€ Solution.java
        β”œβ”€β”€ README.md  (explanation + approach)
    

πŸ“‚ Repository Structure

LeetCode_Trees_Series/
β”‚
β”œβ”€β”€ Binary_Tree/
β”‚   β”œβ”€β”€ 0104_Maximum_Depth_of_Binary_Tree/
β”‚   β”‚   β”œβ”€β”€ Solution.java
β”‚   β”‚   └── README.md
β”‚   β”œβ”€β”€ 0110_Balanced_Binary_Tree/
β”‚   β”‚   β”œβ”€β”€ Solution.java
β”‚   β”‚   └── README.md
β”‚   └── ...
β”‚
β”œβ”€β”€ Binary_Search_Tree/
β”‚   β”œβ”€β”€ 0098_Validate_BST/
β”‚   β”‚   β”œβ”€β”€ Solution.java
β”‚   β”‚   └── README.md
β”‚   β”œβ”€β”€ 0700_Search_in_BST/
β”‚   β”‚   β”œβ”€β”€ Solution.java
β”‚   β”‚   └── README.md
β”‚   └── ...
β”‚
└── Advanced_Trees/
    β”œβ”€β”€ 0297_Serialize_and_Deserialize_BT/
    β”‚   β”œβ”€β”€ Solution.java
    β”‚   └── README.md
    └── ...

🧠 Problem Format

Each problem folder contains:

  • README.md

    • Problem Link
    • Intuition
    • Approach
    • Complexity Analysis (Time & Space)
  • Solution.java

    /**
     * Problem: 104. Maximum Depth of Binary Tree
     * Link: https://leetcode.com/problems/maximum-depth-of-binary-tree/
     *
     * Time Complexity: O(n)
     * Space Complexity: O(h) where h is tree height
     */
    class Solution {
        public int maxDepth(TreeNode root) {
            if (root == null) return 0;
            return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
        }
    }

🎯 Goals of this Repo

  • βœ… Build a complete set of Java tree solutions for LeetCode.
  • βœ… Provide clear explanations + clean code.
  • βœ… Cover both easy, medium, and hard tree problems.
  • βœ… Help students & professionals crack FAANG / top company interviews.

🀝 Contributing

  • Fork the repo & add your solution.
  • Make sure code is properly formatted and commented.
  • Submit a PR πŸš€

⭐ Support

If you find this repository helpful, please star ⭐ it and share with friends preparing for DSA in Java!


About

Java solutions for LeetCode tree problems with explanations, approaches, and clean interview-ready code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages