408. Valid Word Abbreviation

A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their lengths. The lengths should not have leading zeros. For example, a string such as “substitution” could be abbreviated as (but not limited to): “s10n” (“s ubstitutio n”) “sub4u4” (“sub stit u tion”) “12” (“substitution”) “su3i1u2on” (“su bst i t u ti on”) “substitution” (no substrings replaced) The following are not valid abbreviations: “s55n” (“s ubsti tutio n”, the replaced substrings are adjacent) “s010n” (has leading zeros) “s0ubstitution” (replaces an empty substring) Given a string word and an abbreviation abbr, return whether the string matches the given abbreviation....

<span title='2022-01-31 00:00:00 +0000 UTC'>January 31, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

671. Second Minimum Node In a Binary Treer

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node’s value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root.left.val, root.right.val) always holds. Given such a binary tree, you need to output the second minimum value in the set made of all the nodes’ value in the whole tree....

<span title='2022-01-13 00:00:00 +0000 UTC'>January 13, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1009. Complement of Base 10 Integer

The complement of an integer is the integer you get when you flip all the 0’s to 1’s and all the 1’s to 0’s in its binary representation. For example, The integer 5 is “101” in binary and its complement is “010” which is the integer 2. Given an integer n, return its complement. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Example 1: Input: n = 5 Output: 2 Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10....

<span title='2022-01-06 00:00:00 +0000 UTC'>January 6, 2022</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

409. Longest Palindrome

Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, “Aa” is not considered a palindrome here. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Example 1: Input: s = "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7....

<span title='2021-11-28 00:00:00 +0000 UTC'>November 28, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

266. Palindrome Permutation

Given a string s, return true if a permutation of the string could form a palindrome. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: s = "code" Output: false Example 2: Input: s = "aab" Output: true Example 3: Input: s = "carerac" Output: true Constraints: 1 <= s.length <= 5000 s consists of only lowercase English letters. Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 class Solution { public boolean canPermutePalindrome(String s) { int[] freq = new int[256]; for (char c: s....

<span title='2021-11-27 00:00:00 +0000 UTC'>November 27, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

125. Valid Palindrome

A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise. 1 2 3 4 5 Example 1: Input: s = "A man, a plan, a canal: Panama" Output: true Explanation: "amanaplanacanalpanama" is a palindrome....

<span title='2021-11-20 00:00:00 +0000 UTC'>November 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

88. Merge Sorted Array

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored....

<span title='2021-11-20 00:00:00 +0000 UTC'>November 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

26. Remove Duplicates from Sorted Array

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result....

<span title='2021-11-17 00:00:00 +0000 UTC'>November 17, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Pair Sums

Given two integer arrays of equal length target and arr. In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps. Return True if you can make arr equal to target, or False otherwise. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Example 1: Input: target = [1,2,3,4], arr = [2,4,1,3] Output: true Explanation: You can follow the next steps to convert arr to target: 1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3] 2- Reverse sub-array [4,2], arr becomes [1,2,4,3] 3- Reverse sub-array [4,3], arr becomes [1,2,3,4] There are multiple ways to convert arr to target, this is not the only way to do so....

<span title='2021-11-13 00:00:00 +0000 UTC'>November 13, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

704. Binary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: nums = [-1,0,3,5,9,12], target = 2 Output: -1 Explanation: 2 does not exist in nums so return -1 Constraints:...

<span title='2021-11-09 00:00:00 +0000 UTC'>November 9, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1242. Web Crawler Multithreaded

Given a URL startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl. Return all URLs obtained by your web crawler in any order. Your crawler should: Start from the page: startUrl Call HtmlParser.getUrls(url) to get all URLs from a webpage of a given URL. Do not crawl the same link twice. Explore only the links that are under the same hostname as startUrl....

<span title='2021-11-04 00:00:00 +0000 UTC'>November 4, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

1287. Element Appearing More Than 25% In Sorted Array

Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. 1 2 3 4 5 6 7 8 9 Example 1: Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6 Example 2: Input: arr = [1,1] Output: 1 Constraints: 1 <= arr.length <= 10^4 0 <= arr[i] <= 10^5 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 class Solution { public int findSpecialInteger2(int[] arr) { int n = arr....

<span title='2021-10-28 00:00:00 +0000 UTC'>October 28, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

121. Best Time to Buy and Sell Stock

You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. 1 2 3 4 5 6 Example 1: Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5....

<span title='2021-10-20 00:00:00 +0000 UTC'>October 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

415. Add Strings

Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: num1 = "11", num2 = "123" Output: "134" Example 2: Input: num1 = "456", num2 = "77" Output: "533" Example 3: Input: num1 = "0", num2 = "0" Output: "0" Constraints:...

<span title='2021-10-09 00:00:00 +0000 UTC'>October 9, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1662. Check If Two String Arrays are Equivalent

Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. 1 2 3 4 5 6 7 8 Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represents string "ab" + "c" -> "abc" word2 represents string "a" + "bc" -> "abc" The strings are the same, so return true....

<span title='2021-09-16 00:00:00 +0000 UTC'>September 16, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx