Manh PhanPractice makes perfect!
http://ducmanhphan.github.io
Leetcode 441 - Arranging Coins
Table of contents Given problem Using brute force algorithm Using Binary Search algorithm Wrapping up Given problem You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the...
Thu, 02 Feb 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-02-02-leetcode-441-arranging-coins/
http://ducmanhphan.github.io/2023-02-02-leetcode-441-arranging-coins/Leetcode 69 - Sqrt(x)
Table of contents Given problem Using brute force solution Using binary search Wrapping up Given problem Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or...
Tue, 31 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-31-leetcode-69-sqrt(x)/
http://ducmanhphan.github.io/2023-01-31-leetcode-69-sqrt(x)/Leetcode 290 - Word Pattern
Table of contents Given problem Analysis of this problem Solution 1 Solution 2 Wrapping up Given problem Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a...
Sat, 21 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-21-leetcode-290-word-pattern/
http://ducmanhphan.github.io/2023-01-21-leetcode-290-word-pattern/Leetcode 448 - Find All Numbers Disappeared in an Array
Table of contents Given problem Using Cyclic Sort Wrapping up Given problem Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1: Input: nums =...
Tue, 17 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-17-leetcode-448-find-all-numbers-disappeared-in-an-array/
http://ducmanhphan.github.io/2023-01-17-leetcode-448-find-all-numbers-disappeared-in-an-array/Leetcode 209 - Minimum Size Subarray Sum
Table of contents Given problem Using brute-force solution Using Binary Search algorithm with Prefix-sum Wrapping up Given problem Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than...
Mon, 16 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-16-leetcode-209-minimum-size-subarray-sum/
http://ducmanhphan.github.io/2023-01-16-leetcode-209-minimum-size-subarray-sum/Cyclic sort
Table of contents Given problem Solution of Cyclic Sort When to use Benefits and Drawbacks Wrapping up Given problem Given an array nums = {3, 1, 5, 4, 2}. How to use Cyclic sort for this array. Solution of Cyclic Sort When using Cyclic Sort, there are some things that...
Mon, 16 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-16-cyclic-sort/
http://ducmanhphan.github.io/2023-01-16-cyclic-sort/Leetcode 268 - Missing Number
Table of contents Given problem Using brute force solution Using HashMap data structure Using Cyclic Sort Wrapping up Given problem Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums...
Sun, 15 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-15-leetcode-268-missing-number/
http://ducmanhphan.github.io/2023-01-15-leetcode-268-missing-number/Leetcode 287 - Find The Duplicate Number
Table of contents Given problem Using Cyclic Sort Using marker points Wrapping up Given problem 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...
Thu, 05 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-05-leetcode-287-find-the-duplicate-number/
http://ducmanhphan.github.io/2023-01-05-leetcode-287-find-the-duplicate-number/Leetcode 236 - Lowest Common Ancestor Of A Binary Tree
Table of contents Given problem Brute-force Solution Optimized Solution 1 Wrapping up Given problem Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and...
Sun, 01 Jan 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-01-01-leetcode-236-lowest-common-ancestor-of-a-binary-tree/
http://ducmanhphan.github.io/2023-01-01-leetcode-236-lowest-common-ancestor-of-a-binary-tree/Leetcode 543 - Diameter of Binary Tree
Table of contents Given problem Brute-force solution Optimized solution 1 Wrapping up Given problem Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree....
Wed, 28 Dec 2022 00:00:00 -0800
http://ducmanhphan.github.io/2022-12-28-leetcode-543-diameter-of-binary-tree/
http://ducmanhphan.github.io/2022-12-28-leetcode-543-diameter-of-binary-tree/Leetcode 153 - Find Minimum in Rotated Sorted Array
Table of contents Given problem Using Binary Search algorithm Wrapping up Given problem Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [4,5,6,7,0,1,2] if it was rotated 4 times. [0,1,2,4,5,6,7] if it was...
Thu, 26 May 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-05-26-leetcode-153-find-minimum-in-rotated-sorted-array/
http://ducmanhphan.github.io/2022-05-26-leetcode-153-find-minimum-in-rotated-sorted-array/Leetcode 1348 - Tweet Counts Per Frequency
Table of contents Given problem Analyze our problem Using Binary Search algorithm Using TreeMap data structure Using TreeSet data structure Wrapping up Given problem A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These...
Wed, 18 May 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-05-18-leetcode-1348-tweet-counts-per-frequency/
http://ducmanhphan.github.io/2022-05-18-leetcode-1348-tweet-counts-per-frequency/Leetcode 1346 - Check If N and its Double Exists
Table of contents Given problem Using Brute-force solution Using Binary Search algorithm Using other solutions Wrapping up Given problem Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M). More...
Mon, 16 May 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-05-16-leetcode-1346-check-if-n-and-its-double-exist/
http://ducmanhphan.github.io/2022-05-16-leetcode-1346-check-if-n-and-its-double-exist/How to convert int[] to List of Integer
Table of contents Given problem Using Arrays utitlity class Using Collections class Using the traditional for loop Wrapping up Given problem When we work on some projects, or practice coding in LeetCode, sometimes we need to do conversion from int[] to List<Integer>. This is a tedious task. Normally, we will...
Sun, 17 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-17-how-to-convert-int-to-list-integer/
http://ducmanhphan.github.io/2022-04-17-how-to-convert-int-to-list-integer/Leetcode 950 - Reveal Cards In Increasing Order
Table of contents Given problem Using Deque data structure Wrapping up Given problem You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i]. You can order the deck in any order you...
Sun, 10 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-10-leetcode-950-reveal-cards-in-increasing-order/
http://ducmanhphan.github.io/2022-04-10-leetcode-950-reveal-cards-in-increasing-order/Leetcode 1823 - Find the Winner of the Circular Game
Table of contents Given problem Using Circular Linked List Using Queue Wrapping up Given problem There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings...
Thu, 07 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-07-leetcode-1823-find-the-winner-of-the-circular-game/
http://ducmanhphan.github.io/2022-04-07-leetcode-1823-find-the-winner-of-the-circular-game/Leetcode 1413 - Minimum value to get positive step by step sum
Table of contents Given problem Using brute force algorithm Using prefix sum technique Using binary search algorithm Using Kadane algorithm Wrapping up Given problem Given an array of integers nums, you start with an initial positive value startValue. In each iteration, you calculate the step by step sum of startValue...
Thu, 07 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-07-leetcode-1413-minimum-value-to-get-positive-step-by-step-sum/
http://ducmanhphan.github.io/2022-04-07-leetcode-1413-minimum-value-to-get-positive-step-by-step-sum/Leetcode 1700 - Number of Students Unable to Eat Lunch
Table of contents Given problem Using brute force algorithm Optimized the above solution Wrapping up Given problem The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches....
Sat, 02 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-02-leetcode-1700-number-of-students-unable-to-eat-lunch/
http://ducmanhphan.github.io/2022-04-02-leetcode-1700-number-of-students-unable-to-eat-lunch/Leetcode 933 - Number of Recent Calls
Table of contents Given problem Using Queue Using Binary Search algorithm Wrapping up Given problem You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with zero recent requests. int ping(int t) Adds a new...
Fri, 01 Apr 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-04-01-leetcode-933-number-of-recent-calls/
http://ducmanhphan.github.io/2022-04-01-leetcode-933-number-of-recent-calls/Rete algorithm
Table of contents Given problem Solution with Rete algorithm The differences between Rete algorithm and Brute force approach When to use Benefits and Drawbacks Some questions about Rete algorithm Source code Wrapping up Given problem This article will be used to note everything about the simple version of Rete algorithm...
Thu, 31 Mar 2022 00:00:00 -0700
http://ducmanhphan.github.io/2022-03-31-rete-algorithm/
http://ducmanhphan.github.io/2022-03-31-rete-algorithm/