Day - 3
Good afternoon my family! I love your support and it gives me the motivation to make better actions. I am trying to solve problems every day with at least one solution. This is the third day of my coding challenge and I solved 2 problems. I am going to share how I solved it. If you find it useful, share it with your friends. And I would be happy If you start your own challenge because of me. Let's goo to the solutions.
/*
* @param {number[]} nums
* @param {number} n
* @return {number[]}
*/
var shuffle = function (nums, n) {
let res = Array(2 * n);
for (let i = 0; i < n; ++i) {
res[2 * i] = nums[i];
res[2 * i + 1] = nums[n + i];
}
return res;
};
2. Problem 2176. Count Equal and Divisible Pairs in an Array
/*
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var countPairs = function (nums, k) {
let quantity = 0;
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
nums[i] == nums[j] && (i * j) % k === 0 ? quantity++ : null;
}
}
return quantity;
};
Thanks for your attention!!! Wait for the next day. I will come back with other problem solutions! You can check my GitHub and LeetCode profiles as well.
GitHub:
LeetCode: