Skip to content

Instantly share code, notes, and snippets.

View webtaculars's full-sized avatar
🏠

abhishek gupta webtaculars

🏠
View GitHub Profile
// 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(
@webtaculars
webtaculars / Minimum-platforms.js
Created April 9, 2019 03:45
Given arrival and departure times of all trains that reach a railway station. Your task is to find the minimum number of platforms required for the railway station so that no train waits.
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") {
@webtaculars
webtaculars / Equilibrium-point.js
Created April 6, 2019 11:06
Given an array A of N positive numbers. The task is to find the position where equilibrium first occurs in the array. Equilibrium position in an array is a position such that the sum of elements before it is equal to the sum of elements after it.
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];
@webtaculars
webtaculars / Missing-number-in-array.js
Created April 4, 2019 05:32
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.
// 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])
@webtaculars
webtaculars / Kadanes-algo.js
Created April 4, 2019 05:13
Given an array arr of N integers. Find the contiguous sub-array with maximum sum.
// 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
@webtaculars
webtaculars / Subarray-with-given-sum.txt
Created April 3, 2019 17:16
Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S.
// 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) {
@webtaculars
webtaculars / Subarray-with-given-sum.txt
Created April 3, 2019 17:15
Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to a given number S.
// 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) {
@webtaculars
webtaculars / minStep.js
Created March 13, 2019 09:04
minimum steps to move from different points on a grid
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);
}
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]) {
// 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: