Home
Gaurav's GitHub Page
Cancel

Binary Tree Paths

PROBLEM DESCRIPTION Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. Leetcode SOLUTION class Solution { public List<St...

Binary Tree Maximum Path Sum 2

PROBLEM DESCRIPTION A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most onc...

Count Good Nodes in Binary Tree

PROBLEM DESCRIPTION Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in t...

Subtree of Another Tree

PROBLEM DESCRIPTION Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtr...

Balanced Binary Tree

PROBLEM DESCRIPTION Given a binary tree, determine if it is height-balanced. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by mo...

Same Tree

PROBLEM DESCRIPTION Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical,...

Find the Duplicate Number

PROBLEM DESCRIPTION Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated ...

Remove Duplicates from Sorted List

PROBLEM DESCRIPTION Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. leetcode SOLUTION class Soluti...

Rotate List

PROBLEM DESCRIPTION Given the head of a linked list, rotate the list to the right by k places. leetcode SOLUTION APPROACH 1 class Solution { public ListNode rotateRight(ListNode head, int...

Swap Nodes in Pairs

PROBLEM DESCRIPTION Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves...