Regular Expression Matching Regular Expression Matching LeetCode Solution

Problem Statement Regular Expression Matching Regular Expression Matching LeetCode Solution – Given an input string s and a pattern p, implement regular expression matching with support for ‘.’ and ‘*’ where: ‘.’ Matches any single character.​​​​ ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). Example Test Case 1: Input: …

Read more

Serialize and Deserialize Binary Tree LeetCode Solution

Problem Statement Serialize and Deserialize Binary Tree LeetCode Solution – Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in …

Read more

Binary Tree Maximum Path Sum LeetCode Solution

Problem Statement Binary Tree Maximum Path Sum LeetCode Solution – 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 the path does not need …

Read more

Find the Duplicate Number LeetCode Solution

Problem Statement Find the Duplicate Number LeetCode Solution – 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 number. You must solve the problem without modifying the array nums and uses only constant extra space. Input: nums = [1,3,4,2,2] Output: 2 Explanation …

Read more

Product of Array Except Self LeetCode Solution

Problem Statement Product of Array Except Self LeetCode Solution – Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division …

Read more

Intersection of Two Linked Lists LeetCode Solution

Problem Statement Intersection of Two Linked Lists LeetCode Solution – We are given the heads of two strongly linked-lists headA and headB. It is also given that the two linked lists may intersect at some point. We are asked to return the node at which they intersect or null if …

Read more

Permutation Sequence LeetCode Solution

Problem Statement Permutation Sequence LeetCode Solution – The set [1, 2, 3, …, n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence for n = 3: “123” “132” “213” “231” “312” “321” Given n and k, return the kth permutation sequence. Example Test Case 1: Input: n …

Read more

Peeking Iterator LeetCode Solution

Problem Statement Peeking Iterator LeetCode Solution – Design an iterator that supports the peek operation on an existing iterator in addition to the hasNext and the next operations. Implement the PeekingIterator class: PeekingIterator(Iterator<int> nums) Initializes the object with the given integer iterator iterator. int next() Returns the next element in the array and moves the pointer to the next element. boolean …

Read more

Defanging an IP Address LeetCode Solution

Problem Statement Defanging an IP Address LeetCode Solution – Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period “.” with “[.]”. Input: address = “1.1.1.1” Output: “1[.]1[.]1[.]1” Explanation The intuition is very simple. 1. create a Stringbuilder str 2. loop through the address string …

Read more

Translate »