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

1099. Two Sum Less Than K

1099. Two Sum Less Than K Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [34,23,1,24,75,33,54,8], k = 60 Output: 58 Explanation: We can use 34 and 24 to sum 58 which is less than 60. Example 2: Input: nums = [10,20,30], k = 15 Output: -1 Explanation: In this case it is not possible to get a pair sum less that 15. Constraints: ...

June 14, 2021 · 1 min · volyx

19. Remove Nth Node From End of List

19. Remove Nth Node From End of List Given the head of a linked list, remove the nth node from the end of the list and return its head. 1 2 3 4 Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] 1 2 3 4 5 6 7 8 9 Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: ...

June 14, 2021 · 2 min · volyx

2. Add Two Numbers

2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. 1 2 3 4 5 Example 1: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807. ...

June 14, 2021 · 4 min · volyx

523. Continuous Subarray Sum

523. Continuous Subarray Sum Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least two whose elements sum up to a multiple of k, or false otherwise. An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Example 1: Input: nums = [23,2,4,6,7], k = 6 Output: true Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6. Example 2: Input: nums = [23,2,6,4,7], k = 6 Output: true Explanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42. 42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer. Example 3: Input: nums = [23,2,6,4,7], k = 13 Output: false Constraints: ...

June 14, 2021 · 3 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

974. Subarray Sums Divisible by K

974. Subarray Sums Divisible by K Given an array nums of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by k. 1 2 3 4 5 6 Example 1: Input: nums = [4,5,0,-2,-3,1], k = 5 Output: 7 Explanation: There are 7 subarrays with a sum divisible by k = 5: [4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3] Note: ...

June 14, 2021 · 1 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

1898. Maximum Number of Removable Characters

1898. Maximum Number of Removable Characters You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed). You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence. ...

June 13, 2021 · 3 min · volyx

1899. Merge Triplets to Form Target Triplet

1899. Merge Triplets to Form Target Triplet A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain. To obtain target, you may apply the following operation on triplets any number of times (possibly zero): ...

June 13, 2021 · 3 min · volyx