View Program.cs
This file contains 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
using System; | |
using System.Collections.Generic; | |
namespace NumberCombinations | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
View Program.cs
This file contains 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
using System; | |
using System.Linq; | |
namespace minimumDifference | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine(Program.getMinimumDifference(new string[] { "16:15", "16:00", "12:20" })); |
View shuffleClass.js
This file contains 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
const shuffleClass = (classList, count) => { | |
if (isNaN(count) || !Array.isArray(classList)) throw new Error('Invalid input '); | |
let newClassList = []; | |
if (count === 0 || Math.abs(count) >= classList.length) return classList; | |
if (count > 0) { | |
for (let i = classList.length - count; i < classList.length; i++) { | |
newClassList.push(classList[i]); |
View mergeAges.ts
This file contains 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
const mergeAges = (classA: Array<number>, classB: Array<number>) => { | |
let mergedAges: Array<number> = [] | |
let i = 0, j = 0 | |
while(i < classA.length && j < classB.length) { | |
if (isNaN(classA[i]) || isNaN(classB[j])) throw new Error('Invalid input') | |
if (classA[i] <= classB[j]) { | |
mergedAges.push(classA[i++]) |
View arrayProduct.js
This file contains 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
const arrayProduct = nums => { | |
if(!Array.isArray(nums)) throw new Error('Invalid input') | |
let product = 1 | |
let countOfZeros = 0; | |
let productWithoutZeros = 1 | |
for (let i = 0, j = nums.length - 1; i <= j; i++, j--) { | |
if (typeof nums[i] != 'number' || typeof nums[j] != 'number') throw new Error('Invalid input') | |
View startAndEnd.js
This file contains 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
const startAndEnd = (nums, val) => { | |
if (!Array.isArray(nums) || typeof val !== 'number') throw new Error('Invalid input') | |
const min = Math.min(...nums); | |
let positions = [-1, -1] | |
let countLessThanVal = 0 | |
let countOfVal = 0 | |
let countOfMin = 0 |
View removeInstance.js
This file contains 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 removeInstance(nums, val) { | |
if (!Array.isArray(nums)) throw new Error('Invalid input') | |
return nums.filter(entry => entry !== val).length | |
} |
View Sock Merchant Solution in Java
This file contains 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
static int sockMerchant(int n, int[] ar) { | |
Set set = new HashSet<Integer>(); | |
int noOfPairs = 0; | |
for (int i=0; i<n; i++) { | |
if (set.contains(ar[i])) { | |
noOfPairs++; | |
set.remove(ar[i]); | |
} else { | |
set.add(ar[i]); | |
} |
View gist:efd264cd41baa4e820bbbb3e2d6e9895
This file contains 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
import axios from 'axios' | |
const API_ENDPOINT = 'https://sample-flights-api.com/cities/' | |
async function getAirports (cityCodes) { | |
let promises = [] | |
let airports = [] | |
cityCodes.forEach(city => { | |
let promise = new Promise(async (resolve, reject) => { | |
try { | |
let { data } = await axios.get(`${API_ENDPOINT}city`) |