Given an array of positive integersContinue reading “[Leetcode]1590. Make Sum Divisible by P”nums
, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible byp
. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or-1
if it's impossible. A subarray is defined as a contiguous block of elements in the array.
[Leetcode]421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?Continue reading “[Leetcode]421. Maximum XOR of Two Numbers in an Array”
[Leetcode]560. Subarray Sum Equals K
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: 2Continue reading “[Leetcode]560. Subarray Sum Equals K”
[Leetcode]1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].Continue reading “[Leetcode]1. Two Sum”
[Leetcode]1497. Check If Array Pairs Are Divisible by k
Given an array of integersContinue reading “[Leetcode]1497. Check If Array Pairs Are Divisible by k”arr
of even lengthn
and an integerk
. We want to divide the array into exactlyn / 2
pairs such that the sum of each pair is divisible byk
. Return True If you can find a way to do that or False otherwise. Example 1: Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5 Output: true Explanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).