1913. Maximum Product Difference Between Two Pairs

1913. Maximum Product Difference Between Two Pairs The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d). For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16. Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized. ...

June 30, 2021 · 2 min · volyx

1071. Greatest Common Divisor of Strings

1071. Greatest Common Divisor of Strings For two strings s and t, we say “t divides s” if and only if s = t + … + t (t concatenated with itself 1 or more times) Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Example 1: Input: str1 = "ABCABC", str2 = "ABC" Output: "ABC" Example 2: Input: str1 = "ABABAB", str2 = "ABAB" Output: "AB" Example 3: Input: str1 = "LEET", str2 = "CODE" Output: "" Example 4: Input: str1 = "ABCDEF", str2 = "ABC" Output: "" Constraints: ...

June 29, 2021 · 1 min · volyx

204. Count Primes

204. Count Primes Count the number of prime numbers less than a non-negative number, n. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Example 1: Input: n = 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. Example 2: Input: n = 0 Output: 0 Example 3: Input: n = 1 Output: 0 Constraints: ...

June 29, 2021 · 1 min · volyx

83. Remove Duplicates from Sorted List

1625. Lexicographically Smallest String After Applying Operations Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. 1 2 3 4 Example 1: Input: head = [1,1,2] Output: [1,2] 1 2 3 4 Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] ...

June 22, 2021 · 2 min · volyx

1624. Largest Substring Between Two Equal Characters

1624. Largest Substring Between Two Equal Characters Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1. A substring is a contiguous sequence of characters within a string. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Example 1: Input: s = "aa" Output: 0 Explanation: The optimal substring here is an empty substring between the two 'a's. Example 2: Input: s = "abca" Output: 2 Explanation: The optimal substring here is "bc". Example 3: Input: s = "cbzxy" Output: -1 Explanation: There are no characters that appear twice in s. Example 4: Input: s = "cabbac" Output: 4 Explanation: The optimal substring here is "abba". Other non-optimal substrings include "bb" and "". Constraints: ...

June 20, 2021 · 2 min · volyx

206. Reverse Linked List

206. Reverse Linked List Given the head of a singly linked list, reverse the list, and return the reversed list. 1 2 3 4 Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] 1 2 3 4 Example 2: Input: head = [1,2] Output: [2,1] ...

June 17, 2021 · 1 min · volyx

237. Delete Node in a Linked List

237. Delete Node in a Linked List Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list. 1 2 3 4 5 Example 1: Input: head = [4,5,1,9], node = 5 Output: [4,1,9] Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function. ...

June 16, 2021 · 2 min · volyx

680. Valid Palindrome II

680. Valid Palindrome II Given a string s, return true if the s can be palindrome after deleting at most one character from it. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: true Explanation: You could delete the character 'c'. Example 3: Input: s = "abc" Output: false Constraints: ...

June 15, 2021 · 2 min · volyx

67. Add Binary

67. Add Binary Given two binary strings a and b, return their sum as a binary string. 1 2 3 4 5 6 7 8 9 Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: ...

June 14, 2021 · 2 min · volyx

1897. Redistribute Characters to Make All Strings Equal

1897. Redistribute Characters to Make All Strings Equal You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in words equal using any number of operations, and false otherwise. 1 2 3 4 5 6 7 8 9 10 11 12 13 Example 1: Input: words = ["abc","aabc","bc"] Output: true Explanation: Move the first 'a' in words[1] to the front of words[2], to make words[1] = "abc" and words[2] = "abc". All the strings are now equal to "abc", so return true. Example 2: Input: words = ["ab","a"] Output: false Explanation: It is impossible to make all the strings equal using the operation. Constraints: ...

June 13, 2021 · 2 min · volyx