Manh PhanPractice makes perfect!
http://ducmanhphan.github.io
Leetcode 2389 - Longest Subsequence With Limited Sum
Table of contents Given problem Using Backtracking algorithm Using Binary Search algorithm Using Tree Map with Binary Search Using Priority Queue Wrapping up Given problem You are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m...
Tue, 28 Feb 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-02-28-leetcode-2389-longest-subsequence-with-limited-sum/
http://ducmanhphan.github.io/2023-02-28-leetcode-2389-longest-subsequence-with-limited-sum/Leetcode 2089 - Find Target Indices After Sorting Array
Table of contents Given problem Using brute-force Using Binary Search algorithm Using the characteristics of problem Wrapping up Given problem You are given a 0-indexed integer array nums and a target element target. A target index is an index i such that nums[i] == target. Return a list of the...
Wed, 22 Feb 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-02-22-leetcode-2089-find-target-indices-after-sorting-array/
http://ducmanhphan.github.io/2023-02-22-leetcode-2089-find-target-indices-after-sorting-array/Leetcode 540 - Single Element in a Sorted Array
Table of contents Given problem Using XOR bitwise operator Using Binary Search algorithm Wrapping up Given problem You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element that appears only once. Your...
Fri, 17 Feb 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-02-17-leetcode-540-single-element-in-a-sorted-array/
http://ducmanhphan.github.io/2023-02-17-leetcode-540-single-element-in-a-sorted-array/Leetcode 2529 - Maximum Count of Positive Integer and Negative Integer
Table of contents Given problem Using brute-force algorithm Using Binary Search algorithm Wrapping up Given problem Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers. In other words, if the number of positive integers in nums...
Fri, 17 Feb 2023 00:00:00 -0800
http://ducmanhphan.github.io/2023-02-17-leetcode-2529-maximum-count-of-positive-integer-and-negative-integer/
http://ducmanhphan.github.io/2023-02-17-leetcode-2529-maximum-count-of-positive-integer-and-negative-integer/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 Some properties of a rotated array Solutions for this problem Using Linear Search 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]...
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/