This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Install Nodemailer | |
// Enable less secure flag for the email that you will be using to send email https://myaccount.google.com/u/0/lesssecureapps | |
// Update pincode, date, senderEmail, senderPassword, senderName, receiverEmail | |
const https = require("https"); | |
const nodemailer = require("nodemailer"); | |
function runCron(pincode, date) { | |
setInterval(() => { | |
https.get( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minPlatform(arr, dep) { | |
let obj = new Object(); | |
let plat = 0; | |
let result = 0; | |
for (let i = 0; i < arr.length; i++) { | |
obj[arr[i]] = "a"; | |
obj[dep[i]] = "d"; | |
} | |
for (let i of Object.keys(obj)) { | |
if (obj[i] == "a") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function equilibrium(arr) { | |
let lSum = arr[0]; | |
let rSum = arr[arr.length - 1]; | |
let x = 0, | |
y = arr.length - 1; | |
while (lSum !== rSum) { | |
if (lSum > rSum) { | |
rSum = rSum + arr[--y]; | |
} else { | |
lSum = lSum + arr[++x]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an array C of size N-1 and given that there are numbers from 1 to N with one element missing, the missing number is to be found. | |
function missingNum (arr) { | |
let expectedLength = arr.length + 1; | |
let expectedSum = expectedLength * (expectedLength + 1) / 2 | |
let sum = arr.reduce((a, b) => a + b , 0) | |
return expectedSum - sum | |
} | |
missingNum([1, 2, 3, 4, 6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an array arr of N integers. Find the contiguous sub-array with maximum sum. | |
function subarraySum (arr, sum) { | |
let currentSum = arr[0] | |
let max = currentSum; | |
for(let i = 1; i < arr.length; i++) { | |
currentSum = currentSum + arr[i] | |
if(currentSum > max) { | |
max = currentSum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S. | |
function subarraySum (arr, sum) { | |
let currentSum = arr[0] | |
let start = 0; | |
let end = 0 | |
for(let i = 1; currentSum !== sum; i++) { | |
currentSum = currentSum + arr[i] | |
end++; | |
if(currentSum > sum) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S. | |
function subarraySum (arr, sum) { | |
let currentSum = arr[0] | |
let start = 0; | |
let end = 0 | |
for(let i = 1; currentSum !== sum; i++) { | |
currentSum = currentSum + arr[i] | |
end++; | |
if(currentSum > sum) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minSteps(arr) { | |
let n = arr.length; | |
let stepCount = 0; | |
for (let i = 0; i < n - 1; i++) { | |
let x = Math.abs(arr[i].x - arr[i + 1].x); | |
let y = Math.abs(arr[i].y - arr[i + 1].y); | |
stepCount += Math.max(x, y); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sort(arr) { | |
let n = arr.length; | |
for (let i = 0; i < n; i += 2) { | |
if (i > 0 && arr[i - 1] > arr[i]) { | |
let temp = arr[i]; | |
arr[i] = arr[i - 1]; | |
arr[i - 1] = temp; | |
} | |
if (i < n - 1 && arr[i] < arr[i + 1]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scraping: Codewars Top 500 Users | |
// You should get and parse the html of the codewars leaderboard page (https://www.codewars.com/users/leaderboard). | |
// You can use Nokogiri(Ruby) or BeautifulSoup(Python) or CheerioJS(Javascript). | |
// For Javascript: Return a Promise resolved with your 'Leaderboard' Object! | |
// You must meet the following criteria: |