Leetcode 0211. Design Add and Search Words Data Structure

Posted on Tue 05 November 2024 in Leetcode • Tagged with trie-prefix-tree, dfs, recursion

Question Link : https://leetcode.com/problems/design-add-and-search-words-data-structure/

Difficulty: Medium

Premium: False

Question

Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class:

WordDictionary() Initializes the object. void addWord(word) Adds word to the data structure, it can …


Continue reading

Leetcode 0098. Validate Binary Search Tree

Posted on Wed 25 September 2024 in Leetcode • Tagged with bst, recursion

Question Link : https://leetcode.com/problems/validate-binary-search-tree/

Difficulty: Medium

Premium: False

Question

Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the …


Continue reading

Leetcode 0129. Sum Root to Leaf Numbers

Posted on Mon 13 March 2023 in Leetcode • Tagged with recursion, binary-tree

Question Link : https://leetcode.com/problems/sum-root-to-leaf-numbers/

Difficulty: Medium

Premium: False

Question

You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number.

For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.

Return …


Continue reading

Leetcode 0100. Same Tree

Posted on Mon 09 January 2023 in Leetcode • Tagged with binary-tree-traversal, recursion

Question Link : https://leetcode.com/problems/same-tree/

Difficulty: Easy

Premium: False

Question

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, and the nodes have …


Continue reading

Leetcode 0124. Binary Tree Maximum Path Sum

Posted on Sat 10 December 2022 in Leetcode • Tagged with recursion, binary-tree

Question Link : https://leetcode.com/problems/binary-tree-maximum-path-sum/

Difficulty: Hard

Premium: False

Question

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 once. Note that …


Continue reading

Leetcode 0938. Range Sum of BST

Posted on Tue 06 December 2022 in Leetcode • Tagged with bst, recursion

Question Link : https://leetcode.com/problems/range-sum-of-bst/

Difficulty: Easy

Premium: False

Question

Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].   Example 1:

Input: root = [10,5 …


Continue reading

Leetcode 0112. Path Sum

Posted on Tue 04 October 2022 in Leetcode • Tagged with binary-tree, recursion

Question Link : https://leetcode.com/problems/path-sum/

Difficulty: Easy

Question

Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. A leaf is a node with no children …


Continue reading

Leetcode 2293. Min Max Game

Posted on Wed 08 June 2022 in Leetcode • Tagged with recursion, simulation

Question Link : https://leetcode.com/problems/min-max-game/

Difficulty: Easy

Question

You are given a 0-indexed integer array nums whose length is a power of 2. Apply the following algorithm on nums:

Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer …


Continue reading

Leetcode 0138. Copy List with Random Pointer

Posted on Fri 11 March 2022 in Leetcode • Tagged with linked-list, dummy-list-head, recursion

Question Link : https://leetcode.com/problems/copy-list-with-random-pointer/

Difficulty: Medium

Question

A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list. The deep copy should consist …


Continue reading

Leetcode 0509. Fibonacci Number

Posted on Mon 28 February 2022 in Leetcode • Tagged with recursion

Question Link : https://leetcode.com/problems/fibonacci-number/

Difficulty: Easy

Question

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

F(0) = 0, F(1) = 1 F …


Continue reading