Given an array of positive integers
Continue 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 by
p. 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.
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”
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Input:nums = [1,1,1], k = 2 Output: 2
Continue reading “[Leetcode]560. Subarray Sum Equals K”
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.
Given nums = [2, 7, 11, 15], target = 9, Because nums + nums = 2 + 7 = 9, return [0, 1].
Continue reading “[Leetcode]1. Two Sum”
Given an array of integers
Continue reading “[Leetcode]1497. Check If Array Pairs Are Divisible by k”
arr of even length
n and an integer
We want to divide the array into exactly
n / 2 pairs such that the sum of each pair is divisible by
Return True If you can find a way to do that or False otherwise.
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).