├── README.md ├── absoluteValuesSumMinization ├── README.md └── absoluteValuesSumMinization.ts ├── add ├── README.md └── add.ts ├── addBorder ├── README.md └── addBorder.ts ├── addTwoDigits ├── README.md └── addTwoDigits.js ├── adjacentElementsProduct ├── README.md └── adjacentElementsProduct.ts ├── allLongestStrings ├── README.md └── allLongestStrings.ts ├── almostIncreasingSequence ├── README.md └── almostIncreasingSequence.ts ├── alphabetSubSequence ├── README.md └── alphabetSubSequence.ts ├── alphabeticShift ├── README.md └── alphabeticShift.ts ├── alternatingSums ├── README.md └── alternatingSums.ts ├── areEquallyStrong ├── README.md └── areEquallyStrong.ts ├── areSimilar ├── README.md └── areSimilar.ts ├── arrayChange ├── README.md └── arrayChange.ts ├── arrayConversion ├── README.md └── arrayConversion.ts ├── arrayMaxConsecutiveSum ├── README.md └── arrayMaxConsecutiveSum.ts ├── arrayMaximalAdjacentDifference ├── README.md └── arrayMaximalAdjacentDifference.ts ├── arrayPreviousLess ├── README.md └── arrayPreviousLess.ts ├── arrayReplace ├── README.md └── arrayReplace.ts ├── avoidObstacles ├── README.md └── avoidObstacles.ts ├── bishopAndPawn ├── README.md └── bishopAndPawn.ts ├── boxBlur ├── README.md └── boxBlur.ts ├── candies ├── README.md └── candies.ts ├── caseInsensitivePalimdrome ├── README.md └── caseInsensitivePalindrome.ts ├── centuryFromYear ├── README.md └── centuryFromYear.ts ├── characterParity ├── README.md └── characterParity.ts ├── checkPalindrome ├── README.md └── checkPalindrome.ts ├── chessBoardCellColor ├── README.md └── chessBoardCellColor.ts ├── chunkyMonkey ├── README.md └── chunkyMonkey.ts ├── circleOfNumbers ├── README.md └── circleOfNumbers.ts ├── commonCharacterCount ├── README.md └── commonCharacterCount.ts ├── companyBotStrategy ├── README.md └── companyBotStrategy.ts ├── compareIntegers ├── README.md └── compareIntegers.ts ├── composeRanges ├── README.md └── composeRanges.ts ├── confirmEnding ├── README.md └── confirmEnding.ts ├── containsCloseNums ├── README.md └── containsCloseNums.ts ├── containsDuplicates ├── README.md └── containsDuplicates.ts ├── convertCelsiusToFahrenheit ├── README.md └── convertCelsiusToFahrenheit.ts ├── convertString ├── README.md └── convertString.ts ├── crossingSum ├── README.md └── crossingSum.ts ├── depositProfit ├── README.md └── depositProfit.ts ├── differentSymbolsNaive ├── README.md └── differentSymbolsNaive.ts ├── digitDegree ├── README.md └── digitDegree.ts ├── domainType ├── README.md └── domainType.ts ├── electionWinners ├── README.md └── electionWinners.ts ├── encloseInBrackets ├── README.md └── encloseInBrackets.ts ├── evenDigitsOnly ├── README.md └── evenDigitsOnly.ts ├── extractEachKth ├── README.md └── extractEachKth.ts ├── extractMatrixColumn ├── README.md └── extractMatrixColumn.ts ├── factorializeANumber ├── README.md └── factorializeANumber.ts ├── fancyRide ├── README.md └── fancyRide.ts ├── fareEstimator ├── README.md └── fareEstimator.ts ├── fermactor ├── README.md └── fermactor.ts ├── findClosestPair ├── README.md └── findClosestPair.ts ├── findEmailDomain ├── README.md └── findEmailDomain.ts ├── firstDigit ├── README.md └── firstDigit.ts ├── firstDuplicate ├── README.md └── firstDuplicate.ts ├── firstNotRepeatingCharacter ├── README.md └── firstNotRepeatingCharacter.ts ├── flattenArray ├── README.md └── flattenArray.ts ├── growingPlant ├── README.md └── growingPlant.ts ├── houseNumbersSum ├── README.md └── houseNumbersSum.ts ├── houseOfCats ├── README.md └── houseOfCats.ts ├── htmlEndTagByStartTag ├── README.md └── htmlEndTagByStartTag.ts ├── incorrectPasswordAttempts ├── README.md └── incorrectPasswordAttempts.ts ├── incrementalBackups ├── README.md └── incrementalBackups.ts ├── integerToStringOfWixedWidth ├── README.md └── integerToStringOfFixedWidth.ts ├── isLucky ├── README.md └── isLucky.ts ├── isTandemRepeat ├── README.md └── isTandemRepeat.ts ├── largestNumber ├── README.md └── largestNumber.ts ├── largestOfFour ├── README.md └── largestOfFour.ts ├── lateRide ├── README.md └── lateRide.ts ├── launchSequenceChecker ├── README.md └── launchSequenceChecker.ts ├── longestDigitsPrefix ├── README.md └── longestDigitsPrefix.ts ├── makeArrayConsecutive2 ├── README.md └── makeArrayConsecutive2.ts ├── matrixElementsSum ├── README.md └── matrixElementsSum.ts ├── maxMultiple ├── README.md └── maxMultiple.ts ├── mineSweeper ├── README.md └── mineSweeper.ts ├── minimalNumberOfCoins ├── README.md └── minimalNumberOfCoins.ts ├── missingLetters ├── README.md └── missingLetters.ts ├── mostFrequentDigitSum ├── README.md └── mostFrequentDigitSum.ts ├── newNumeralSystem ├── README.md └── newNumeralSystem.ts ├── pagesNumberingWithInk ├── README.md └── pagesNumberingWithInk.ts ├── palindromeRearranging ├── README.md └── palindromeRearranging.ts ├── pigLatin ├── README.md └── pigLatin.ts ├── proCategorization ├── README.md └── proCategorization.ts ├── properNounCorrection ├── README.md └── properNounCorrection.ts ├── ratingThreshold ├── README.md └── ratingThreshold.ts ├── reflectString ├── README.md └── reflectString.ts ├── reverseAString ├── README.md └── reverseAString.ts ├── seatsInTheater ├── README.md └── seatsInTheater.ts ├── seekAndDestroy ├── README.md └── seekAndDestroy.ts ├── shapeArea ├── README.md └── shapeArea.ts ├── sortByHeight ├── README.md └── sortByHeight.ts ├── sortByLength ├── README.md └── sortByLength.ts ├── squareDigitsSequence ├── README.md └── squareDigitSequence.ts ├── stolenLunch ├── README.md └── stolenLunch.ts ├── stringsConstruction ├── README.md └── stringsConstruction.ts ├── sumAllPrimes ├── README.md └── sumAllPrimes.ts ├── sumOddFibonacciNums ├── README.md └── sumOddFibonacciNums.ts ├── sumOfTwo ├── README.md └── sumOfTwo.ts ├── switchLights ├── README.md └── switchLights.ts ├── tasksType ├── README.md └── tasksType.ts ├── uniqueDigitProducts ├── README.md └── uniqueDigitsProducts.ts └── validTime ├── README.md └── validTime.ts /README.md: -------------------------------------------------------------------------------- 1 | Check Out My YouTube Channel 2 | 3 | # 100AlgorithmsChallenge 4 | 5 | 6 |

This is the setup for my Udemy Course: The 100 Algorithms Challenge: How to Ace the JavaScript Coding Interview.

7 |

There are 100 algorithms with README instructions as well as the initial function setup with a few test cases.

8 | -------------------------------------------------------------------------------- /absoluteValuesSumMinization/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | --- 3 | Given a sorted array of integers a, find an integer x from a such that the value of 4 | 5 | abs(a[0] - x) + abs(a[1] - x) + ... + abs(a[a.length - 1] - x) 6 | is the smallest possible (here abs denotes the absolute value). 7 | If there are several possible answers, output the smallest one. 8 | 9 | **Example** 10 | 11 | For a = [2, 4, 7], the output should be 12 | absoluteValuesSumMinimization(a) = 4. 13 | 14 | For a = [2, 4, 7, 6], the output should be 15 | absoluteValuesSumMinimization(a) = 4. 16 | 17 | For a = [2, 4, 7, 6, 6], the output should be 18 | absoluteValuesSumMinimization(a) = 7. 19 | 20 | For a = [2, 4, 7, 6, 6, 8], the output should be 21 | absoluteValuesSumMinimization(a) = 7. 22 | 23 | **Hints** 24 | - Math.floor() 25 | 26 | **Input/Output** 27 | 28 | - **[time limit] 4000ms (js)** 29 | - **[input] array.integer a** 30 | 31 | A non-empty array of integers, sorted in ascending order. 32 | 33 | *Guaranteed constraints:* 34 | 35 | 1 ≤ a.length ≤ 200, 36 | 37 | -106 ≤ a[i] ≤ 106. 38 | 39 | - **[output] integer** -------------------------------------------------------------------------------- /absoluteValuesSumMinization/absoluteValuesSumMinization.ts: -------------------------------------------------------------------------------- 1 | function absoluteValuesSumMinimization(a: number[]): number { 2 | const isEven = a.length % 2 === 0; 3 | 4 | return isEven ? a[a.length / 2 - 1] : a[Math.floor(a.length / 2)]; 5 | } 6 | 7 | console.log(absoluteValuesSumMinimization([2, 4, 7])); 8 | console.log(absoluteValuesSumMinimization([2, 4, 7, 6])); 9 | console.log(absoluteValuesSumMinimization([2, 4, 7, 6, 6])); 10 | console.log(absoluteValuesSumMinimization([2, 4, 7, 6, 6, 8])); -------------------------------------------------------------------------------- /add/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | 1. Write a function that returns the sum of two numbers. 5 | 2. Write a function that returns the sum of all numbers regardless of # of params. 6 | 7 | **Example** 8 | 9 | For param1 = 1 and param2 = 2, the output should be 10 | add(param1, param2) = 3. 11 | 12 | **Hints** 13 | - Arithmetic Operators 14 | - Rest Operator 15 | - forEach() 16 | 17 | **Input/Output** 18 | 19 | - **[time limit] 4000ms (js)** 20 | - **[input] integer param1** 21 | 22 | Guaranteed constraints: 23 | 24 | -100 ≤ param1 ≤ 1000. 25 | 26 | **[input] integer param2** 27 | 28 | Guaranteed constraints: 29 | -100 ≤ param2 ≤ 1000. 30 | 31 | **[output] integer** 32 | 33 | The sum of the two inputs. -------------------------------------------------------------------------------- /add/add.ts: -------------------------------------------------------------------------------- 1 | function add(param1: number, param2: number): number { 2 | return param1 + param2; 3 | } 4 | 5 | function add2(...param1: number[]): number { 6 | let total = 0; 7 | param1.map((num) => { 8 | total += num; 9 | }); 10 | 11 | return total; 12 | } 13 | 14 | console.log(add(1, 2)); 15 | console.log(add(3, 2)); 16 | 17 | console.log(add2(1,2,3,4,5)); 18 | console.log(add2(2,3)); 19 | 20 | -------------------------------------------------------------------------------- /addBorder/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | --- 3 | Given a rectangular matrix of characters, add a border of asterisks(*) to it. 4 | 5 | **Example** 6 | 7 | For 8 | 9 | picture = ["abc", 10 | "ded"] 11 | the output should be 12 | 13 | addBorder(picture) = ["*****", 14 | "*abc*", 15 | "*ded*", 16 | "*****"] 17 | 18 | **Hints** 19 | - concat() 20 | - unshift() 21 | - push() 22 | 23 | **Input/Output** 24 | - **[time limit] 4000ms (js)** 25 | - **[input] array.string picture** 26 | 27 | A non-empty array of non-empty equal-length strings. 28 | 29 | *Guaranteed constraints:* 30 | 31 | 1 ≤ picture.length ≤ 5, 32 | 33 | 1 ≤ picture[i].length ≤ 5. 34 | 35 | - **[output] array.string** 36 | 37 | The same matrix of characters, framed with a border of asterisks of width 1. -------------------------------------------------------------------------------- /addBorder/addBorder.ts: -------------------------------------------------------------------------------- 1 | function addBorder(picture: string[]): any { 2 | const wall = '*'.repeat(picture[0].length + 2); 3 | 4 | picture.unshift(wall); 5 | picture.push(wall); 6 | 7 | for (let i = 1; i < picture.length - 1; i++) { 8 | picture[i] = '*'.concat(picture[i], '*'); 9 | } 10 | 11 | return picture; 12 | } 13 | 14 | console.log(addBorder(["abc", "ded"])); -------------------------------------------------------------------------------- /addTwoDigits/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | You are given a two-digit integer n. Return the sum of its digits. 5 | 6 | **Example** 7 | 8 | For n = 29, the output should be 9 | addTwoDigits(n) = 11. 10 | 11 | **Hint** 12 | - split() 13 | - parseInt() 14 | - toString() 15 | - reduce() 16 | 17 | **Input/Output** 18 | 19 | - **[execution time limit] 4 seconds (js)** 20 | - **[input] integer n** 21 | 22 | A positive two-digit integer. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 10 ≤ n ≤ 99. 27 | 28 | - **[output] integer** 29 | 30 | The sum of the first and second digits of the input number. 31 | 32 | -------------------------------------------------------------------------------- /addTwoDigits/addTwoDigits.js: -------------------------------------------------------------------------------- 1 | function addTwoDigits(n) { 2 | const numbers = n.toString().split(''); 3 | 4 | return numbers.reduce((a, b) => { 5 | return parseInt(a) + parseInt(b) 6 | }); 7 | } 8 | 9 | console.log(addTwoDigits(29)); -------------------------------------------------------------------------------- /adjacentElementsProduct/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | 5 | Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. 6 | 7 | **Example** 8 | 9 | For inputArray = [3, 6, -2, -5, 7, 3], the output should be 10 | adjacentElementsProduct(inputArray) = 21. 11 | 12 | 7 and 3 produce the largest product. 13 | 14 | **Hints** 15 | - None 16 | 17 | **Input/Output** 18 | 19 | - **[time limit] 4000ms (js)** 20 | - **[input] array.integer inputArray** 21 | 22 | An array of integers containing at least two elements. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 2 ≤ inputArray.length ≤ 10, 27 | -1000 ≤ inputArray[i] ≤ 1000. 28 | 29 | - **[output] integer** 30 | 31 | The largest product of adjacent elements. -------------------------------------------------------------------------------- /adjacentElementsProduct/adjacentElementsProduct.ts: -------------------------------------------------------------------------------- 1 | function adjacentElementsProduct(inputArray: number[]): number { 2 | let largestNumber = inputArray[0] * inputArray[1]; 3 | 4 | inputArray.map((number, i) => { 5 | largestNumber = number * inputArray[i+1] > largestNumber ? number * inputArray[i+1] : largestNumber; 6 | }) 7 | 8 | return largestNumber; 9 | 10 | } 11 | 12 | console.log(adjacentElementsProduct([3, 6, -2, -5, 7, 3])); -------------------------------------------------------------------------------- /allLongestStrings/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | Given an array of strings, return another array containing all of its longest strings. 5 | 6 | **Example** 7 | 8 | For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be 9 | allLongestStrings(inputArray) = ["aba", "vcd", "aba"]. 10 | 11 | **Hints** 12 | - None 13 | 14 | **Input/Output** 15 | 16 | - **[time limit] 4000ms (js)** 17 | - **[input] array.string inputArray** 18 | 19 | A non-empty array. 20 | 21 | *Guaranteed constraints:* 22 | 23 | 1 ≤ inputArray.length ≤ 10, 24 | 25 | 1 ≤ inputArray[i].length ≤ 10. 26 | 27 | - **[output] array.string** 28 | 29 | Array of the longest strings, stored in the same order as in the inputArray. -------------------------------------------------------------------------------- /allLongestStrings/allLongestStrings.ts: -------------------------------------------------------------------------------- 1 | function allLongestStrings(inputArray: string[]): string[] { 2 | inputArray = inputArray.sort((a, b) => b.length - a.length ) // Sort by length of characters 3 | 4 | const longestArray = inputArray.filter((string) => { 5 | return string.length >= inputArray[0].length; 6 | }); 7 | 8 | return longestArray; 9 | } 10 | 11 | console.log(allLongestStrings(["aba", "aa", "ad", "vcd", "aba"])); -------------------------------------------------------------------------------- /almostIncreasingSequence/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. 5 | 6 | **Example** 7 | 8 | - For sequence = [1, 3, 2, 1], the output should be 9 | almostIncreasingSequence(sequence) = false; 10 | 11 | There is no one element in this array that can be removed in order to get a strictly increasing sequence. 12 | 13 | - For sequence = [1, 3, 2], the output should be 14 | almostIncreasingSequence(sequence) = true. 15 | 16 | You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you can remove 2 to get the strictly increasing sequence [1, 3]. 17 | 18 | **Hints** 19 | - Nope 20 | 21 | **Input/Output** 22 | 23 | - **[time limit] 4000ms (js)** 24 | - **[input] array.integer sequence** 25 | 26 | *Guaranteed constraints:* 27 | 28 | 2 ≤ sequence.length ≤ 105, 29 | 30 | -105 ≤ sequence[i] ≤ 105. 31 | 32 | **[output] boolean** 33 | 34 | Return true if it is possible to remove one element from the array in order to get a strictly increasing sequence, otherwise return false. -------------------------------------------------------------------------------- /almostIncreasingSequence/almostIncreasingSequence.ts: -------------------------------------------------------------------------------- 1 | function almostIncreasingSequence(sequence: number[]): boolean { 2 | let count = 0; 3 | 4 | sequence.map((num, i) => { 5 | if(num <= sequence[i-1]) { 6 | count++; 7 | if(num <= sequence[i-2] && sequence[i+1] <= sequence[i-1]) { 8 | return false; 9 | } 10 | } 11 | }) 12 | 13 | return count <= 1; 14 | } 15 | 16 | // find first wrong and remove 17 | // If the soreted version is equal to original, then true 18 | // else falls 19 | 20 | console.log(almostIncreasingSequence([1, 3, 2, 1])) 21 | console.log(almostIncreasingSequence([1, 3, 2])) -------------------------------------------------------------------------------- /alphabetSubSequence/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | Check whether the given string is a subsequence of the plaintext alphabet. 5 | 6 | **Example** 7 | 8 | - For s = "effg" or s = "cdce", the output should be 9 | alphabetSubsequence(s) = false 10 | 11 | - For s = "ace" or s = "bxz", the output should be 12 | alphabetSubsequence(s) = true. 13 | 14 | **Hints** 15 | - size property 16 | - charCodeAt() 17 | 18 | **Input/Output** 19 | 20 | - **[execution time limit] 5 seconds (ts)** 21 | - **[input] string s** 22 | 23 | *Guaranteed constraints:* 24 | 25 | 2 ≤ s.length ≤ 15. 26 | 27 | **[output] boolean** 28 | 29 | true if the given string is a subsequence of the alphabet, false otherwise. -------------------------------------------------------------------------------- /alphabetSubSequence/alphabetSubSequence.ts: -------------------------------------------------------------------------------- 1 | function alphabetSubsequence(s: string): boolean { 2 | const charCodes = s.split(''); 3 | const chars = []; 4 | 5 | charCodes.forEach((char) => { 6 | chars.push(char.charCodeAt(0)); 7 | }) 8 | 9 | if (new Set(chars).size !== chars.length) { 10 | return false; 11 | } 12 | 13 | for(let i = 0; i < chars.length; i++) { 14 | if(chars[i] >= chars[i + 1]) { 15 | return false; 16 | } 17 | } 18 | 19 | return true; 20 | 21 | 22 | } 23 | 24 | console.log(alphabetSubsequence('zab')) 25 | console.log(alphabetSubsequence('effg')) 26 | console.log(alphabetSubsequence('cdce')) 27 | console.log(alphabetSubsequence('ace')) 28 | console.log(alphabetSubsequence('bxz')) 29 | -------------------------------------------------------------------------------- /alphabeticShift/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | --- 4 | Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a). 5 | 6 | **Example** 7 | 8 | For inputString = "crazy", the output should be 9 | alphabeticShift(inputString) = "dsbaz". 10 | 11 | **Hints** 12 | 13 | - split() 14 | - indexOf() 15 | - join() 16 | 17 | **Input/Output** 18 | 19 | - **[time limit] 4000ms (js)** 20 | - **[input] string inputString** 21 | 22 | Non-empty string consisting of lowercase English characters. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 1 ≤ inputString.length ≤ 10. 27 | 28 | - **[output] string** 29 | 30 | The result string after replacing all of its characters. -------------------------------------------------------------------------------- /alphabeticShift/alphabeticShift.ts: -------------------------------------------------------------------------------- 1 | function alphabeticShift(inputString: string): string { 2 | const alphabet = ('abcdefghijklmnopqrstuvwxyz').split('') 3 | 4 | const string = inputString.split('').map((char) => { 5 | const i = alphabet.indexOf(char); 6 | return alphabet[i+1] !== undefined ? alphabet[i+1] : 'a' 7 | }).join(''); 8 | 9 | return string; 10 | } 11 | 12 | console.log(alphabeticShift('crazy')); -------------------------------------------------------------------------------- /alternatingSums/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-4/cC5QuL9fqvZjXJsW9) 4 | --- 5 | Several people are standing in a row and need to be divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1 again, the fourth into team 2, and so on. 6 | 7 | You are given an array of positive integers - the weights of the people. Return an array of two integers, where the first element is the total weight of team 1, and the second element is the total weight of team 2 after the division is complete. 8 | 9 | **Example** 10 | 11 | For a = [50, 60, 60, 45, 70], the output should be 12 | alternatingSums(a) = [180, 105]. 13 | 14 | **Input/Output** 15 | 16 | - **[time limit] 4000ms (js)** 17 | - **[input] array.integer a** 18 | 19 | *Guaranteed constraints:* 20 | 21 | 1 ≤ a.length ≤ 10, 22 | 23 | 45 ≤ a[i] ≤ 100. 24 | 25 | **[output] array.integer** 26 | -------------------------------------------------------------------------------- /alternatingSums/alternatingSums.ts: -------------------------------------------------------------------------------- 1 | function alternatingSums(a: number[]): number[] { 2 | let team1 = []; 3 | let team2 = []; 4 | let allTeams = []; 5 | 6 | a.map((num, i) => { 7 | i % 2 === 0 ? team1.push(num) : team2.push(num); 8 | }); 9 | 10 | allTeams.push(team1.reduce((a, b) => a + b), team2.reduce((a, b) => a + b)); 11 | 12 | return allTeams; 13 | } 14 | 15 | console.log(alternatingSums([50, 60, 60, 45, 70])) -------------------------------------------------------------------------------- /areEquallyStrong/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-5/g6dc9KJyxmFjB98dL) 4 | --- 5 | Call two arms equally strong if the heaviest weights they each are able to lift are equal. 6 | 7 | Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. 8 | 9 | Given your and your friend's arms' lifting capabilities find out if you two are equally strong. 10 | 11 | **Example** 12 | 13 | - For yourLeft = 10, yourRight = 15, friendsLeft = 15 and friendsRight = 10, the output should be 14 | areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true; 15 | - For yourLeft = 15, yourRight = 10, friendsLeft = 15 and friendsRight = 10, the output should be 16 | areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true; 17 | - For yourLeft = 15, yourRight = 10, friendsLeft = 15 and friendsRight = 9, the output should be 18 | areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = false. 19 | 20 | **Hints** 21 | - None 22 | 23 | **Input/Output** 24 | 25 | - **[time limit] 4000ms (js)** 26 | - **[input] integer yourLeft** 27 | 28 | A non-negative integer representing the heaviest weight you can lift with your left arm. 29 | 30 | *Guaranteed constraints:* 31 | 32 | 0 ≤ yourLeft ≤ 20. 33 | 34 | - **[input] integer yourRight** 35 | 36 | A non-negative integer representing the heaviest weight you can lift with your right arm. 37 | 38 | *Guaranteed constraints:* 39 | 40 | 0 ≤ yourRight ≤ 20. 41 | 42 | - **[input] integer friendsLeft** 43 | 44 | A non-negative integer representing the heaviest weight your friend can lift with his or her left arm. 45 | 46 | *Guaranteed constraints:* 47 | 48 | 0 ≤ friendsLeft ≤ 20. 49 | 50 | - **[input] integer friendsRight** 51 | 52 | A non-negative integer representing the heaviest weight your friend can lift with his or her right arm. 53 | 54 | *Guaranteed constraints:* 55 | 56 | 0 ≤ friendsRight ≤ 20. 57 | 58 | - **[output] boolean** 59 | 60 | true if you and your friend are equally strong, false otherwise. -------------------------------------------------------------------------------- /areEquallyStrong/areEquallyStrong.ts: -------------------------------------------------------------------------------- 1 | function areEquallyStrong(yourLeft: number, yourRight: number, friendsLeft: number, friendsRight: number): boolean { 2 | return yourLeft + yourRight === friendsLeft + friendsRight; 3 | } 4 | 5 | console.log(areEquallyStrong(10, 15, 15, 10)) 6 | console.log(areEquallyStrong(15, 10, 15, 10)) 7 | console.log(areEquallyStrong(15, 10, 15, 9)) 8 | -------------------------------------------------------------------------------- /areSimilar/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-4/xYXfzQmnhBvEKJwXP) 4 | --- 5 | Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays. 6 | 7 | Given two arrays a and b, check whether they are similar. 8 | 9 | **Example** 10 | 11 | - For a = [1, 2, 3] and b = [1, 2, 3], the output should be 12 | areSimilar(a, b) = true. 13 | 14 | The arrays are equal, no need to swap any elements. 15 | 16 | - For a = [1, 2, 3] and b = [2, 1, 3], the output should be 17 | areSimilar(a, b) = true. 18 | 19 | We can obtain b from a by swapping 2 and 1 in b. 20 | 21 | - For a = [1, 2, 2] and b = [2, 1, 1], the output should be 22 | areSimilar(a, b) = false. 23 | 24 | Any swap of any two elements either in a or in b won't make a and b equal. 25 | 26 | **Hints** 27 | - toString() 28 | - reverse() 29 | 30 | **Input/Output** 31 | 32 | - **[time limit] 4000ms (js)** 33 | - **[input] array.integer a** 34 | 35 | Array of integers. 36 | 37 | *Guaranteed constraints:* 38 | 39 | 3 ≤ a.length ≤ 105, 40 | 41 | 1 ≤ a[i] ≤ 1000. 42 | 43 | - **[input] array.integer b** 44 | 45 | Array of integers of the same length as a. 46 | 47 | *Guaranteed constraints:* 48 | 49 | b.length = a.length, 50 | 51 | 1 ≤ b[i] ≤ 1000. 52 | 53 | **[output] boolean** 54 | 55 | true if a and b are similar, false otherwise. -------------------------------------------------------------------------------- /areSimilar/areSimilar.ts: -------------------------------------------------------------------------------- 1 | function areSimilar(a: number[], b: number[]): boolean { 2 | return a.sort().join('') === b.sort().join(''); 3 | } 4 | 5 | console.log(areSimilar([1, 2, 3], [1, 2, 3])); 6 | console.log(areSimilar([1, 2, 3], [2, 1, 3])); 7 | console.log(areSimilar([1, 2, 2], [2, 1, 1])); 8 | -------------------------------------------------------------------------------- /arrayChange/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-4/xvkRbxYkdHdHNCKjg) 4 | --- 5 | You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input. 6 | 7 | **Example** 8 | 9 | For inputArray = [1, 1, 1], the output should be 10 | arrayChange(inputArray) = 3. 11 | 12 | **Input/Output** 13 | 14 | - **[time limit] 4000ms (js)** 15 | - **[input] array.integer inputArray** 16 | 17 | *Guaranteed constraints:* 18 | 19 | 3 ≤ inputArray.length ≤ 105, 20 | 21 | -105 ≤ inputArray[i] ≤ 105. 22 | 23 | - **[output] integer** 24 | 25 | The minimal number of moves needed to obtain a strictly increasing sequence from inputArray. 26 | It's guaranteed that for the given test cases the answer always fits signed 32-bit integer type. -------------------------------------------------------------------------------- /arrayChange/arrayChange.ts: -------------------------------------------------------------------------------- 1 | function arrayChange(inputArray: number[]): number { 2 | 3 | } 4 | 5 | console.log(arrayChange([1, 1, 1])); -------------------------------------------------------------------------------- /arrayConversion/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/spring-of-integration/dwA8RtDF86WucuoaQ) 4 | --- 5 | Given an array of 2k integers (for some integer k), perform the following operations until the array contains only one element: 6 | 7 | - On the 1st, 3rd, 5th, etc. iterations (1-based) replace each pair of consecutive elements with their sum; 8 | - On the 2nd, 4th, 6th, etc. iterations replace each pair of consecutive elements with their product. 9 | After the algorithm has finished, there will be a single element left in the array. Return that element. 10 | 11 | **Example** 12 | 13 | For inputArray = [1, 2, 3, 4, 5, 6, 7, 8], the output should be 14 | arrayConversion(inputArray) = 186. 15 | 16 | We have [1, 2, 3, 4, 5, 6, 7, 8] -> [3, 7, 11, 15] -> [21, 165] -> [186], so the answer is 186. 17 | 18 | **Hints** 19 | - push() 20 | 21 | **Input/Output** 22 | 23 | - **[execution time limit] 5 seconds (ts)** 24 | - **[input] array.integer inputArray** 25 | 26 | *Guaranteed constraints:* 27 | 28 | 1 ≤ inputArray.length ≤ 20, 29 | 30 | -9 ≤ inputArray[i] ≤ 99. 31 | 32 | - **[output] integer** 33 | -------------------------------------------------------------------------------- /arrayConversion/arrayConversion.ts: -------------------------------------------------------------------------------- 1 | function arrayConversion(inputArray: number[]): number { 2 | const finalArray = inputArray.concat(); 3 | let odd = false; 4 | 5 | while(finalArray.length !== 1 ) { 6 | for(var i = 0; i < finalArray.length; i++) { 7 | const sum = odd ? finalArray[i] * finalArray[i + 1] : finalArray[i] + finalArray[i + 1]; 8 | finalArray.splice(i, 2, sum); 9 | } 10 | odd = !odd; 11 | } 12 | 13 | return finalArray.reduce((a, b) => a + b); 14 | } 15 | 16 | console.log(arrayConversion([1, 2, 3, 4, 5, 6, 7, 8])); 17 | -------------------------------------------------------------------------------- /arrayMaxConsecutiveSum/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-4/xvkRbxYkdHdHNCKjg) 4 | --- 5 | Given array of integers, find the maximal possible sum of some of its k consecutive elements. 6 | 7 | **Example** 8 | 9 | For inputArray = [2, 3, 5, 1, 6] and k = 2, the output should be 10 | arrayMaxConsecutiveSum(inputArray, k) = 8. 11 | All possible sums of 2 consecutive elements are: 12 | - 2 + 3 = 5; 13 | - 3 + 5 = 8; 14 | - 5 + 1 = 6; 15 | - 1 + 6 = 7. 16 | 17 | Thus, the answer is 8 18 | 19 | **Input/Output** 20 | 21 | - **[execution time limit] 4 seconds (js)** 22 | - **[input] array.integer inputArray** Array of positive integers. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 3 ≤ inputArray.length ≤ 105, 27 | 28 | 1 ≤ inputArray[i] ≤ 1000. 29 | 30 | - **[input] integer k** 31 | 32 | An integer (not greater than the length of inputArray). 33 | 34 | *Guaranteed constraints:* 35 | 1 ≤ k ≤ inputArray.length. 36 | 37 | - **[output] integer** 38 | 39 | The maximal possible sum. -------------------------------------------------------------------------------- /arrayMaxConsecutiveSum/arrayMaxConsecutiveSum.ts: -------------------------------------------------------------------------------- 1 | function arrayMaxConsecutiveSum(inputArray: number[], k: number): number { 2 | 3 | } 4 | 5 | console.log(arrayMaxConsecutiveSum([2, 3, 5, 1, 6], 2)); -------------------------------------------------------------------------------- /arrayMaximalAdjacentDifference/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | #### Algorithm Walkthrough Video 3 | [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/VGfYf9o3mQo/0.jpg)](http://www.youtube.com/watch?v=VGfYf9o3mQo) 4 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-5/c1xDc8pp__o) 5 | --- 6 | Given an array of integers, find the maximal absolute difference between any two of its adjacent elements. 7 | 8 | **Example** 9 | 10 | For inputArray = [2, 4, 1, 0], the output should be 11 | arrayMaximalAdjacentDifference(inputArray) = 3. 12 | 13 | **Hints** 14 | - Math.abs() 15 | 16 | **Input/Output** 17 | 18 | - **[time limit] 4000ms (js)** 19 | - **[input] array.integer inputArray** 20 | 21 | *Guaranteed constraints:* 22 | 23 | 3 ≤ inputArray.length ≤ 10, 24 | 25 | -15 ≤ inputArray[i] ≤ 15. 26 | 27 | - **[output] integer** 28 | 29 | The maximal absolute difference. -------------------------------------------------------------------------------- /arrayMaximalAdjacentDifference/arrayMaximalAdjacentDifference.ts: -------------------------------------------------------------------------------- 1 | function arrayMaximalAdjacentDifference(inputArray: number[]): number { 2 | 3 | } 4 | 5 | console.log(arrayMaximalAdjacentDifference([2, 4, 1, 0])); -------------------------------------------------------------------------------- /arrayPreviousLess/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/spring-of-integration/MQg7s3dKrP4caN42A) 4 | --- 5 | Given array of integers, for each position i, search among the previous positions for the last (from the left) position that contains a smaller value. Store this value at position i in the answer. If no such value can be found, store -1 instead. 6 | 7 | **Example** 8 | 9 | For items = [3, 5, 2, 4, 5], the output should be 10 | arrayPreviousLess(items) = [-1, 3, -1, 2, 4]. 11 | 12 | **Hints** 13 | - unshift() 14 | 15 | **Input/Output** 16 | 17 | - **[execution time limit] 5 seconds (ts)** 18 | - **[input] array.integer items** 19 | 20 | Non-empty array of positive integers. 21 | 22 | *Guaranteed constraints:* 23 | 24 | 3 ≤ items.length ≤ 15, 25 | 26 | 1 ≤ items[i] ≤ 200. 27 | 28 | - **[output] array.integer** 29 | 30 | Array containing answer values computed as described above. -------------------------------------------------------------------------------- /arrayPreviousLess/arrayPreviousLess.ts: -------------------------------------------------------------------------------- 1 | function arrayPreviousLess(items: number[]): number[] { 2 | 3 | } 4 | 5 | console.log(arrayPreviousLess([3, 5, 2, 4, 5])); -------------------------------------------------------------------------------- /arrayReplace/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-6/mCkmbxdMsMTjBc3Bm) 4 | --- 5 | Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. 6 | 7 | **Example** 8 | 9 | For inputArray = [1, 2, 1], elemToReplace = 1 and substitutionElem = 3, the output should be 10 | arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3]. 11 | 12 | **Input/Output** 13 | 14 | - **[time limit] 4000ms (js)** 15 | - **[input] array.integer inputArray** 16 | 17 | *Guaranteed constraints:* 18 | 19 | 2 ≤ inputArray.length ≤ 10, 20 | 21 | 0 ≤ inputArray[i] ≤ 10. 22 | 23 | - **[input] integer elemToReplace** 24 | 25 | *Guaranteed constraints:* 26 | 27 | 0 ≤ elemToReplace ≤ 10. 28 | 29 | - **[input] integer substitutionElem** 30 | 31 | *Guaranteed constraints:* 32 | 33 | 0 ≤ substitutionElem ≤ 10. 34 | 35 | **[output] array.integer** -------------------------------------------------------------------------------- /arrayReplace/arrayReplace.ts: -------------------------------------------------------------------------------- 1 | function arrayReplace(inputArray: number[], elemToReplace: number, substitutionElem: number): number[] { 2 | 3 | } 4 | 5 | console.log(arrayReplace([1, 2, 1], 1, 3)); -------------------------------------------------------------------------------- /avoidObstacles/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-5/XC9Q2DhRRKQrfLhb5) 4 | --- 5 | 6 | You are given an array of integers representing coordinates of obstacles situated on a straight line. 7 | 8 | Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer. 9 | 10 | Find the minimal length of the jump enough to avoid all the obstacles. 11 | 12 | **Example** 13 | 14 | For inputArray = [5, 3, 6, 7, 9], the output should be 15 | avoidObstacles(inputArray) = 4. 16 | 17 | Check out the image below for better understanding: 18 | 19 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/avoidObstacles/img/example.png?_tm=1490625560816) 20 | 21 | **Hints** 22 | - sort() 23 | - every() 24 | 25 | **Input/Output** 26 | 27 | - **[time limit] 4000ms (js)** 28 | - **[input] array.integer inputArray** 29 | 30 | Non-empty array of positive integers. 31 | 32 | *Guaranteed constraints:* 33 | 34 | 2 ≤ inputArray.length ≤ 10, 35 | 36 | 1 ≤ inputArray[i] ≤ 40. 37 | 38 | - **[output] integer** 39 | 40 | The desired length. -------------------------------------------------------------------------------- /avoidObstacles/avoidObstacles.ts: -------------------------------------------------------------------------------- 1 | function avoidObstacles(inputArray: number[]): number { 2 | 3 | } 4 | 5 | console.log(avoidObstacles([5, 3, 6, 7, 9])); -------------------------------------------------------------------------------- /bishopAndPawn/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-9/AACpNbZANCkhHWNs3) 4 | --- 5 | Given the positions of a white bishop and a black pawn on the standard chess board, determine whether the bishop can capture the pawn in one move. 6 | 7 | The bishop has no restrictions in distance for each move, but is limited to diagonal movement. Check out the example below to see how it can move: 8 | 9 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/bishopAndPawn/img/bishop.jpg?_tm=1493360096740) 10 | 11 | **Example** 12 | 13 | - For bishop = "a1" and pawn = "c3", the output should be 14 | bishopAndPawn(bishop, pawn) = true. 15 | 16 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/bishopAndPawn/img/ex1.jpg?_tm=1493360096945) 17 | 18 | **Hint** 19 | - parseInt() 20 | 21 | **Input/Output** 22 | 23 | - **[time limit] 4000ms (js)** 24 | - **[input] string bishop** 25 | 26 | Coordinates of the white bishop in the chess notation. 27 | 28 | - **[input] string pawn** 29 | 30 | Coordinates of the black pawn in the same notation. 31 | 32 | - **[output] boolean** 33 | 34 | true if the bishop can capture the pawn, false otherwise. -------------------------------------------------------------------------------- /bishopAndPawn/bishopAndPawn.ts: -------------------------------------------------------------------------------- 1 | function bishopAndPawn(bishop: string, pawn: string): boolean { 2 | 3 | } 4 | 5 | console.log(bishopAndPawn('a1', 'c3')); -------------------------------------------------------------------------------- /boxBlur/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-5/5xPitc3yT3dqS7XkP) 4 | --- 5 | Last night you had to study, but decided to party instead. Now there is a black and white photo of you that is about to go viral. You cannot let this ruin your reputation, so you want to apply box blur algorithm to the photo to hide its content. 6 | 7 | The algorithm works as follows: each pixel x in the resulting image has a value equal to the average value of the input image pixels' values from the 3 × 3 square with the center at x. All pixels at the edges are cropped. 8 | 9 | As pixel's value is an integer, all fractions should be rounded down. 10 | 11 | **Example** 12 | 13 | For 14 | 15 | image = [[1, 1, 1], 16 | [1, 7, 1], 17 | [1, 1, 1]] 18 | the output should be boxBlur(image) = [[1]]. 19 | 20 | In the given example all boundary pixels were cropped, and the value of the pixel in the middle was obtained as (1 + 1 + 1 + 1 + 7 + 1 + 1 + 1 + 1) / 9 = 15 / 9 = ~rounded down~ = 1. 21 | 22 | **Hints** 23 | - push() 24 | - Math.floor() 25 | 26 | **Input/Output** 27 | 28 | - **[time limit] 4000ms (js)** 29 | - **[input] array.array.integer image** 30 | 31 | An image is stored as a rectangular matrix of non-negative integers. 32 | 33 | *Guaranteed constraints:* 34 | 35 | 3 ≤ image.length ≤ 10, 36 | 37 | 3 ≤ image[0].length ≤ 10, 38 | 39 | 0 ≤ image[i][j] ≤ 255. 40 | 41 | - **[output] array.array.integer** 42 | 43 | A blurred image. -------------------------------------------------------------------------------- /boxBlur/boxBlur.ts: -------------------------------------------------------------------------------- 1 | function boxBlur(image: number[][]): number[][] { 2 | 3 | } 4 | 5 | console.log(boxBlur([[1, 1, 1], 6 | [1, 7, 1], 7 | [1, 1, 1]])); -------------------------------------------------------------------------------- /candies/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-9/AACpNbZANCkhHWNs3) 4 | --- 5 | n children have got m pieces of candy. They want to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children together. Individual pieces of candy cannot be split. 6 | 7 | **Example** 8 | 9 | - For n = 3 and m = 10, the output should be 10 | candies(n, m) = 9. 11 | 12 | Each child will eat 3 pieces. So the answer is 9. 13 | 14 | **Hints** 15 | - Math.floor() 16 | 17 | **Input/Output** 18 | 19 | - **[execution time limit] 4 seconds (js)** 20 | 21 | - **[input] integer n** 22 | 23 | The number of children. 24 | *Guaranteed constraints:* 1 ≤ n ≤ 10. 25 | 26 | - **[input] integer m** 27 | The number of pieces of candy. 28 | *Guaranteed constraints:* 2 ≤ m ≤ 100. 29 | 30 | - [output] integer 31 | The total number of pieces of candy the children will eat provided they eat as much as they can and all children eat the same amount. -------------------------------------------------------------------------------- /candies/candies.ts: -------------------------------------------------------------------------------- 1 | function candies(n: number, m: number): number { 2 | 3 | } 4 | 5 | console.log(candies(3, 10)); -------------------------------------------------------------------------------- /caseInsensitivePalimdrome/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/book-market/G9wj2j6zaWwFWsise) 4 | --- 5 | Given a string, check if it can become a palindrome through a case change of some (possibly, none) letters. 6 | 7 | **Example** 8 | 9 | - For inputString = "AaBaa", the output should be 10 | isCaseInsensitivePalindrome(inputString) = true. 11 | 12 | "aabaa" is a palindrome as well as "AABAA", "aaBaa", etc 13 | 14 | - For inputString = "abac", the output should be 15 | isCaseInsensitivePalindrome(inputString) = false. 16 | 17 | All the strings which can be obtained via changing case of some group of letters, i.e. "abac", "Abac", "aBAc" and 13 more, are not palindromes. 18 | 19 | **Hints** 20 | - join() 21 | - reverse() 22 | - toLowerCase() 23 | - split() 24 | 25 | 26 | **Input/Output** 27 | 28 | - **[execution time limit] 5 seconds (ts)** 29 | 30 | - **[input] string inputString** 31 | 32 | Non-empty string consisting of English letters. 33 | *Guaranteed constraints:* 4 ≤ inputString.length ≤ 10 34 | 35 | - **[output] boolean** -------------------------------------------------------------------------------- /caseInsensitivePalimdrome/caseInsensitivePalindrome.ts: -------------------------------------------------------------------------------- 1 | function isCaseInsensitivePalindrome(inputString: string): boolean { 2 | 3 | } 4 | 5 | console.log(isCaseInsensitivePalindrome('AaBaa')); 6 | console.log(isCaseInsensitivePalindrome('abac')); -------------------------------------------------------------------------------- /centuryFromYear/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 3 | 4 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-1/egbueTZRRL5Mm4TXN) 5 | --- 6 | Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc. 7 | 8 | **Example** 9 | 10 | - For year = 1905, the output should be 11 | centuryFromYear(year) = 20; 12 | - For year = 1700, the output should be 13 | centuryFromYear(year) = 17. 14 | 15 | **Hints** 16 | - Math.floor() 17 | 18 | **Input/Output** 19 | 20 | - **[time limit] 4000ms (js)** 21 | - **[input] integer year** 22 | 23 | A positive integer, designating the year. 24 | 25 | *Guaranteed constraints:* 26 | 27 | 1 ≤ year ≤ 2005. 28 | 29 | - **[output] integer** 30 | 31 | The number of the century the year is in. -------------------------------------------------------------------------------- /centuryFromYear/centuryFromYear.ts: -------------------------------------------------------------------------------- 1 | function centuryFromYear(year: number): number { 2 | 3 | } 4 | 5 | console.log(centuryFromYear(1905)); 6 | console.log(centuryFromYear(1700)); -------------------------------------------------------------------------------- /characterParity/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 3 | 4 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/lab-of-transformations/QKnGhkoi4wKr6xY9b) 5 | --- 6 | Given a character, check if it represents an odd digit, an even digit or not a digit at all. 7 | 8 | **Example** 9 | 10 | - For symbol = '5', the output should be 11 | characterParity(symbol) = "odd"; 12 | - For symbol = '8', the output should be 13 | characterParity(symbol) = "even"; 14 | - For symbol = 'q', the output should be 15 | characterParity(symbol) = "not a digit". 16 | 17 | **Hints** 18 | - isNaN() 19 | - parseInt() 20 | 21 | **Input/Output** 22 | 23 | - **[execution time limit] 5 seconds (ts)** 24 | - **[input] char symbol** 25 | - **[output] string** 26 | -------------------------------------------------------------------------------- /characterParity/characterParity.ts: -------------------------------------------------------------------------------- 1 | function characterParity(symbol: string): string { 2 | 3 | } 4 | 5 | console.log(characterParity('5')) 6 | console.log(characterParity('8')) 7 | console.log(characterParity('q')) 8 | -------------------------------------------------------------------------------- /checkPalindrome/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://www.youtube.com/watch?v=IVoOmPDCHCM) 4 | --- 5 | Given the string, check if it is a palindrome. 6 | 7 | **Example** 8 | 9 | - For inputString = "aabaa", the output should be 10 | checkPalindrome(inputString) = true; 11 | - For inputString = "abac", the output should be 12 | checkPalindrome(inputString) = false; 13 | - For inputString = "a", the output should be 14 | checkPalindrome(inputString) = true. 15 | 16 | **Hints** 17 | - toLowerCase() 18 | - split() 19 | - reverse() 20 | - join() 21 | 22 | **Input/Output** 23 | 24 | - **[time limit] 4000ms (js)** 25 | - **[input] string inputString** 26 | 27 | A non-empty string consisting of lowercase characters. 28 | 29 | *Guaranteed constraints:* 30 | 31 | 1 ≤ inputString.length ≤ 105. 32 | 33 | **[output] boolean** 34 | 35 | true if inputString is a palindrome, false otherwise. 36 | -------------------------------------------------------------------------------- /checkPalindrome/checkPalindrome.ts: -------------------------------------------------------------------------------- 1 | function checkPalindrome(inputString: string): boolean { 2 | 3 | } 4 | 5 | console.log(checkPalindrome('aabaa')); 6 | console.log(checkPalindrome('abac')); 7 | console.log(checkPalindrome('a')); 8 | -------------------------------------------------------------------------------- /chessBoardCellColor/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-6/t97bpjfrMDZH8GJhi) 4 | --- 5 | Given two cells on the standard chess board, determine whether they have the same color or not. 6 | 7 | **Example** 8 | 9 | - For cell1 = "A1" and cell2 = "C3", the output should be 10 | chessBoardCellColor(cell1, cell2) = true. 11 | 12 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/chessBoardCellColor/img/example1.png?_tm=1494338560912); 13 | 14 | - For cell1 = "A1" and cell2 = "H3", the output should be 15 | chessBoardCellColor(cell1, cell2) = false. 16 | 17 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/chessBoardCellColor/img/example2.png?_tm=1494338561188) 18 | 19 | **Hints** 20 | - parseInt() 21 | 22 | **Input/Output** 23 | 24 | - **[time limit] 4000ms (js)** 25 | - **[input] string cell1** 26 | - **[input] string cell2** 27 | - **[output] boolean** 28 | 29 | true if both cells have the same color, false otherwise. -------------------------------------------------------------------------------- /chessBoardCellColor/chessBoardCellColor.ts: -------------------------------------------------------------------------------- 1 | function chessBoardCellColor(cell1: string, cell2: string): boolean { 2 | 3 | } 4 | 5 | console.log(chessBoardCellColor('A1', 'C3')); 6 | console.log(chessBoardCellColor('A1', 'H3')); 7 | -------------------------------------------------------------------------------- /chunkyMonkey/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ### Check Out More Algorithms like this at FreeCodeCamp 4 | --- 5 | Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array. 6 | 7 | **Example** 8 | - chunkyMonkey(["a", "b", "c", "d"], 2) should return [["a", "b"], ["c", "d"]]. 9 | - chunkyMonkey([0, 1, 2, 3, 4, 5], 4) should return [[0, 1, 2, 3], [4, 5]]. 10 | 11 | **Hints** 12 | - slice() -------------------------------------------------------------------------------- /chunkyMonkey/chunkyMonkey.ts: -------------------------------------------------------------------------------- 1 | function chunkyMonkey(arr: any[], size: number): any[][] { 2 | 3 | } 4 | 5 | console.log(chunkyMonkey(["a", "b", "c", "d"], 2)); 6 | console.log(chunkyMonkey([0, 1, 2, 3, 4, 5], 4)); -------------------------------------------------------------------------------- /circleOfNumbers/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-7/vExYvcGnFsEYSt8nQ) 4 | --- 5 | Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighbouring numbers is equal (note that 0 and n - 1 are neighbouring, too). 6 | 7 | Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber. 8 | 9 | **Example** 10 | 11 | For n = 10 and firstNumber = 2, the output should be 12 | circleOfNumbers(n, firstNumber) = 7. 13 | 14 | ![](https://codefightsuserpics.s3.amazonaws.com/tasks/circleOfNumbers/img/example.png?_tm=1490625697098) 15 | 16 | **Hints** 17 | - push() 18 | 19 | **Input/Output** 20 | 21 | - **[time limit] 4000ms (js)** 22 | - **[input] integer n** 23 | 24 | A positive even integer. 25 | 26 | *Guaranteed constraints:* 27 | 28 | 4 ≤ n ≤ 20. 29 | 30 | - **[input] integer firstNumber** 31 | 32 | *Guaranteed constraints:* 33 | 34 | 0 ≤ firstNumber ≤ n - 1. 35 | 36 | - **[output] integer** -------------------------------------------------------------------------------- /circleOfNumbers/circleOfNumbers.ts: -------------------------------------------------------------------------------- 1 | function circleOfNumbers(n: number, firstNumber: number): number { 2 | 3 | } 4 | 5 | console.log(circleOfNumbers(10, 2)); -------------------------------------------------------------------------------- /commonCharacterCount/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-3/JKKuHJknZNj4YGL32) 4 | --- 5 | Given two strings, find the number of common characters between them. 6 | 7 | **Example** 8 | 9 | For s1 = "aabcc" and s2 = "adcaa", the output should be 10 | commonCharacterCount(s1, s2) = 3. 11 | 12 | Strings have 3 common characters - 2 "a"s and 1 "c". 13 | 14 | **Hints** 15 | - split() 16 | - hasOwnProperty() 17 | 18 | **Input/Output** 19 | 20 | - **[time limit] 4000ms (js)** 21 | - **[input] string s1** 22 | 23 | A string consisting of lowercase latin letters a-z. 24 | 25 | *Guaranteed constraints:* 26 | 27 | 1 ≤ s1.length ≤ 15. 28 | 29 | - **[input] string s2** 30 | 31 | A string consisting of lowercase latin letters a-z. 32 | 33 | *Guaranteed constraints:* 34 | 35 | 1 ≤ s2.length ≤ 15. 36 | 37 | **[output] integer** -------------------------------------------------------------------------------- /commonCharacterCount/commonCharacterCount.ts: -------------------------------------------------------------------------------- 1 | function commonCharacterCount(s1: string, s2: string): number { 2 | 3 | } 4 | 5 | console.log(commonCharacterCount('aabcc', 'adcaa')); -------------------------------------------------------------------------------- /companyBotStrategy/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/codefights/gJMBmTwHHMF8mbQvH) 4 | --- 5 | All four trainers have solved the task correctly, so the answer is (3 + 6 + 4 + 5) / 4 = 4.5. 6 | Each CodeFights Company Bot is trained by engineers from that specific company. The way it works is that a representative group of engineers from each company is identified as trainers before the bot goes live, and they CodeFight against the bot during a training phase. The current training algorithm is definitely more complex, but let's assume it works this way: 7 | 8 | For each trainer we collect two pieces of information per task [answerTime, correctness], where correctness is 1 if the answer was correct, -1 if the answer was wrong, and 0 if no answer was given. In this case, the bot's correct answer time for a given task would be the average of the answer times from the trainers who answered correctly. Given all of the training information for a specific task, calculate the bot's answer time. 9 | 10 | **Example** 11 | - For 12 | 13 | trainingData = [[3, 1], 14 | [6, 1], 15 | [4, 1], 16 | [5, 1]] 17 | the output should be companyBotStrategy(trainingData) = 4.5. 18 | 19 | - For 20 | 21 | trainingData = [[4, 1], 22 | [4, -1], 23 | [0, 0], 24 | [6, 1]] 25 | the output should be companyBotStrategy(trainingData) = 5.0. 26 | 27 | Only the 1st and the 4th trainers (1-based) submitted correct solutions, so the answer is (4 + 6) / 2 = 5.0. 28 | 29 | - For 30 | 31 | trainingData = [[4, -1], 32 | [0, 0], 33 | [5, -1]] 34 | the output should be companyBotStrategy(trainingData) = 0.0. 35 | 36 | No correct answers were given for the task. 37 | 38 | **Input/Output** 39 | 40 | - **[execution time limit] 5 seconds (ts)** 41 | - **[input] array.array.integer trainingData** 42 | The ith element of trainingData contains exactly 2 elements: trainingData[i][0] is the answer time for the ith person and trainingData[i][1] is correctness. 43 | 44 | If a trainer answered correctly, then correctness equals 1; 45 | If a trainer answered incorrectly, then correctness equals -1; 46 | If a trainer didn't give any answer, answerTime and correctness both equal to 0. 47 | 48 | *Guaranteed constraints:* 49 | 50 | 1 ≤ trainingData.length ≤ 20. 51 | 52 | - **[output] float** 53 | 54 | The time the bot will take to solve a specific task. Return 0 if none of the trainers answered correctly. Your output will be considered correct if its absolute error does not exceed 10-5 compared to our tests. -------------------------------------------------------------------------------- /companyBotStrategy/companyBotStrategy.ts: -------------------------------------------------------------------------------- 1 | function companyBotStrategy(trainingData: number[][]): number { 2 | 3 | } 4 | 5 | console.log(companyBotStrategy([[3, 1], [6, 1], [4, 1], [5, 1]])); 6 | console.log(companyBotStrategy([[4, 1], [4, -1], [0, 0], [6, 1]])); 7 | console.log(companyBotStrategy( [[4, -1], [0, 0], [5, -1]])); 8 | -------------------------------------------------------------------------------- /compareIntegers/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/codefights/gJMBmTwHHMF8mbQvH) 4 | --- 5 | Compare two integers given as strings. 6 | 7 | **Example** 8 | - For a = "12" and b = "13", the output should be compareIntegers(a, b) = "less"; 9 | 10 | - For a = "875" and b = "799", the output should be compareIntegers(a, b) = "greater"; 11 | 12 | - For a = "1000" and b = "1000", the output should be compareIntegers(a, b) = "equal". 13 | 14 | **Hints** 15 | - parseInt() 16 | 17 | **Input/Output** 18 | 19 | - **[execution time limit] 5 seconds (ts)** 20 | - **[input] string a** 21 | A string representing a positive integer without leading zeroes. 22 | 23 | *Guaranteed constraints:* 24 | 25 | 1 ≤ a.length ≤ 10. 26 | 27 | - **[input] string b** 28 | 29 | A string representing a positive integer without leading zeroes. 30 | 31 | *Guaranteed constraints:* 32 | 1 ≤ b.length ≤ 10 33 | 34 | - **[output] string** 35 | 'less' if int(a) < int(b), 'equal' if int(a) = int(b), and 'greater' if int(a) > int(b), where int(x) is equal to integer represented by the string x. -------------------------------------------------------------------------------- /compareIntegers/compareIntegers.ts: -------------------------------------------------------------------------------- 1 | function compareIntegers(a: string, b: string): string { 2 | 3 | } 4 | 5 | console.log(compareIntegers('12', '13')); 6 | console.log(compareIntegers('875', '799')); 7 | console.log(compareIntegers('1000', '1000')); -------------------------------------------------------------------------------- /composeRanges/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/interview-practice/task/cHYqbQ9DiWmejAdeG) 4 | --- 5 | Given a sorted integer array that does not contain any duplicates, return a summary of the number ranges it contains. 6 | 7 | **Example** 8 | - For nums = [-1, 0, 1, 2, 6, 7, 9], the output should be 9 | composeRanges(nums) = ["-1->2", "6->7", "9"]. 10 | 11 | **Hints** 12 | - push() 13 | 14 | **Input/Output** 15 | 16 | - **[execution time limit] 5 seconds (ts)** 17 | - **[input] array.integer nums** 18 | A sorted array of unique integers. 19 | 20 | *Guaranteed constraints:* 21 | 22 | 0 ≤ nums.length ≤ 15, 23 | (231 - 1) ≤ nums[i] ≤ 231 - 1. 24 | 25 | - **[output] array.string** -------------------------------------------------------------------------------- /composeRanges/composeRanges.ts: -------------------------------------------------------------------------------- 1 | function composeRanges(nums: number[]): string[] { 2 | 3 | } 4 | 5 | 6 | console.log(composeRanges([-1, 0, 1, 2, 6, 7, 9])); -------------------------------------------------------------------------------- /confirmEnding/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ### Check Out More Algorithms like this at FreeCodeCamp 4 | --- 5 | 6 | Check if a string (first argument, str) ends with the given target string (second argument, target). 7 | 8 | This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead. 9 | 10 | Remember to use Read-Search-Ask if you get stuck. Write your own code. 11 | 12 | **Example** 13 | - confirmEnding("Abstraction", "action") returns true; 14 | - confirmEnding("Open sesame", "pen") returns false; 15 | 16 | **Hints** 17 | - substr() -------------------------------------------------------------------------------- /confirmEnding/confirmEnding.ts: -------------------------------------------------------------------------------- 1 | function confirmEnding(str: string, target: string) { 2 | 3 | } 4 | 5 | console.log(confirmEnding("Abstraction", "action")); 6 | console.log(confirmEnding("Open sesame", "pen")); -------------------------------------------------------------------------------- /containsCloseNums/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/interview-practice/task/njfXsvjRthFKmMwLC) 4 | --- 5 | Given an array of integers nums and an integer k, determine whether there are two distinct indices i and j in the array where nums[i] = nums[j] and the absolute difference between i and j is less than or equal to k. 6 | 7 | **Example** 8 | - For nums = [0, 1, 2, 3, 5, 2] and k = 3, the output should be 9 | containsCloseNums(nums, k) = true. 10 | 11 | There are two 2s in nums, and the absolute difference between their positions is exactly 3. 12 | 13 | - For nums = [0, 1, 2, 3, 5, 2] and k = 2, the output should be 14 | 15 | containsCloseNums(nums, k) = false. 16 | 17 | The absolute difference between the positions of the two 2s is 3, which is more than k. 18 | 19 | **Hints** 20 | - Math.abs() 21 | 22 | **Input/Output** 23 | 24 | - **[execution time limit] 5 seconds (ts)** 25 | - **[input] array.integer nums** 26 | A string representing a positive integer without leading zeroes. 27 | 28 | *Guaranteed constraints:* 29 | 30 | 0 ≤ nums.length ≤ 55000, 31 | -231 - 1 ≤ nums[i] ≤ 231 - 1. 32 | 33 | - **[input] integer k** 34 | 35 | *Guaranteed constraints:* 36 | 37 | 0 ≤ k ≤ 35000. 38 | 39 | - **[output] boolean** 40 | -------------------------------------------------------------------------------- /containsCloseNums/containsCloseNums.ts: -------------------------------------------------------------------------------- 1 | function containsCloseNums(nums: number[], k: number): boolean { 2 | 3 | } 4 | 5 | console.log(containsCloseNums([0, 1, 2, 3, 5, 2], 3)); 6 | console.log(containsCloseNums([0, 1, 2, 3, 5, 2], 2)); -------------------------------------------------------------------------------- /containsDuplicates/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/interview-practice/task/CfknJzPmdbstXhsoJ) 4 | --- 5 | Given an array of integers, write a function that determines whether the array contains any duplicates. Your function should return true if any element appears at least twice in the array, and it should return false if every element is distinct. 6 | 7 | **Example** 8 | - For a = [1, 2, 3, 1], the output should be 9 | containsDuplicates(a) = true. 10 | 11 | There are two 1s in the given array. 12 | 13 | - For a = [3, 1], the output should be 14 | containsDuplicates(a) = false. 15 | 16 | The given array contains no duplicates. 17 | 18 | **Hints** 19 | - sort() 20 | 21 | **Input/Output** 22 | 23 | - **[execution time limit] 5 seconds (ts)** 24 | - **[input] array.integer a** 25 | A sorted array of unique integers. 26 | 27 | *Guaranteed constraints:* 28 | 29 | 0 ≤ a.length ≤ 105, 30 | -2 · 109 ≤ a[i] ≤ 2 · 109. 31 | 32 | - **[output] boolean** -------------------------------------------------------------------------------- /containsDuplicates/containsDuplicates.ts: -------------------------------------------------------------------------------- 1 | function containsDuplicates(a: number[]): boolean { 2 | 3 | } 4 | 5 | console.log(containsDuplicates([1, 2, 3, 1])); 6 | console.log(containsDuplicates([3, 1])); 7 | -------------------------------------------------------------------------------- /convertCelsiusToFahrenheit/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | --- 3 | 4 | The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. 5 | 6 | You are given a variable celsius representing a temperature in Celsius. Use the variable fahrenheit already defined and assign it the Fahrenheit temperature equivalent to the given Celsius temperature. Use the algorithm mentioned above to help convert the Celsius temperature to Fahrenheit. 7 | 8 | Don't worry too much about the function and return statements as they will be covered in future challenges. For now, only use operators that you have already learned. 9 | 10 | **Example** 11 | - celsiusToFahrenheit(-30) returns -22; 12 | - celsiusToFahrenheit(-10) returns 14; 13 | - celsiusToFahrenheit(0) returns 32; -------------------------------------------------------------------------------- /convertCelsiusToFahrenheit/convertCelsiusToFahrenheit.ts: -------------------------------------------------------------------------------- 1 | function celsiusToFahrenheit(celsius: number): number { 2 | 3 | } 4 | 5 | console.log(celsiusToFahrenheit(-30)); 6 | console.log(celsiusToFahrenheit(-10)); 7 | console.log(celsiusToFahrenheit(0)); -------------------------------------------------------------------------------- /convertString/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/challenge/DF6j9AcQSCGtLonyM) 4 | --- 5 | You are given the string s. Your friend just asked you if it's possible to change the string from s to a string t by removing some characters from it. You're a pro at programming, so you decided to create a program to determine this. 6 | 7 | **Example** 8 | - For s = "ceoydefthf5iyg5h5yts" and t = "codefights", the output should be 9 | convertString(s, t) = true. 10 | 11 | - For s = "addbyca" and t = "abcd", the output should be 12 | convertString(s, t) = false. 13 | 14 | **Hints** 15 | - concat() 16 | - split() 17 | 18 | **Input/Output** 19 | 20 | - **[execution time limit] 4 seconds (js)** 21 | - **[input] string s** 22 | A string with alphanumeric characters. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 1 ≤ s.length ≤ 1000. 27 | 28 | - **[input] string t** 29 | 30 | A string with alphanumeric characters. 31 | 32 | *Guaranteed constraints:* 33 | 1 ≤ t.length ≤ 1000. 34 | 35 | - **[output] boolean** 36 | Return true if it is possible to convert s to t, otherwise return false. -------------------------------------------------------------------------------- /convertString/convertString.ts: -------------------------------------------------------------------------------- 1 | function convertString(s: string, t: string): boolean { 2 | 3 | } 4 | 5 | console.log(convertString('ceoydefthf5iyg5h5yts', 'codefights')); 6 | console.log(convertString('addbyca', 'abcd')); 7 | -------------------------------------------------------------------------------- /crossingSum/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/list-backwoods/Nh48Nqxb2zGx2NvYK) 4 | --- 5 | Given a rectangular matrix and integers a and b, consider the union of the ath row and the bth (both 0-based) column of the matrix (i.e. all cells that belong either to the ath row or to the bth column, or to both). Return sum of all elements of that union. 6 | 7 | **Example** 8 | - For 9 | 10 | matrix = [[1, 1, 1, 1], 11 | [2, 2, 2, 2], 12 | [3, 3, 3, 3]] 13 | a = 1 and b = 3, the output should be 14 | crossingSum(matrix, a, b) = 12. 15 | 16 | Here (2 + 2 + 2 + 2) + (1 + 3) = 12. 17 | 18 | **Hints** 19 | - reduce() 20 | 21 | **Input/Output** 22 | 23 | - **[execution time limit] 4 seconds (js)** 24 | - **[input] array.array.integer matrix** 25 | 2-dimensional array of integers representing a rectangular matrix. 26 | 27 | *Guaranteed constraints:* 28 | 29 | 1 ≤ matrix.length ≤ 5, 30 | 1 ≤ matrix[0].length ≤ 5, 31 | 1 ≤ matrix[i][j] ≤ 100. 32 | 33 | - **[input] integer a** 34 | A non-negative integer less than the number of matrix rows. 35 | 36 | *Guaranteed constraints:* 37 | 0 ≤ a < matrix.length. 38 | 39 | - **[input] integer b** 40 | A non-negative integer less than the number of matrix columns. 41 | 42 | *Guaranteed constraints:* 43 | 0 ≤ b < matrix[i].length. 44 | 45 | - **[output] integer** 46 | -------------------------------------------------------------------------------- /crossingSum/crossingSum.ts: -------------------------------------------------------------------------------- 1 | function crossingSum(matrix: number[][], a: number, b: number): number { 2 | 3 | } 4 | 5 | console.log(crossingSum([[1, 1, 1, 1], 6 | [2, 2, 2, 2], 7 | [3, 3, 3, 3]], 1, 3)); -------------------------------------------------------------------------------- /depositProfit/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-7/8PxjMSncp9ApA4DAb) 4 | --- 5 | You have deposited a specific amount of dollars into your bank account. Each year your balance increases at the same growth rate. Find out how long it would take for your balance to pass a specific threshold with the assumption that you don't make any additional deposits. 6 | 7 | **Example** 8 | 9 | For deposit = 100, rate = 20 and threshold = 170, the output should be 10 | depositProfit(deposit, rate, threshold) = 3. 11 | 12 | Each year the amount of money on your account increases by 20%. It means that throughout the years your balance would be: 13 | 14 | - **year 0: 100;** 15 | - **year 1: 120;** 16 | - **year 2: 144;** 17 | - **year 3: 172,8.** 18 | 19 | Thus, it will take 3 years for your balance to pass the threshold, which is the answer. 20 | 21 | **Input/Output** 22 | 23 | - **[time limit] 4000ms (js)** 24 | - **[input] integer deposit** 25 | 26 | The initial deposit as a positive integer. 27 | 28 | *Guaranteed constraints:* 29 | 30 | 1 ≤ deposit ≤ 100. 31 | 32 | - **[input] integer rate** 33 | 34 | The rate of increase. Each year the balance increases by the rate percent of the current sum. 35 | 36 | Guaranteed constraints: 37 | 1 ≤ rate ≤ 100. 38 | 39 | - **[input] integer threshold** 40 | 41 | The target balance. 42 | 43 | *Guaranteed constraints:* 44 | 45 | deposit < threshold ≤ 200. 46 | 47 | - **[output] integer** 48 | 49 | The number of years it would take to hit the threshold. -------------------------------------------------------------------------------- /depositProfit/depositProfit.ts: -------------------------------------------------------------------------------- 1 | function depositProfit(deposit: number, rate: number, threshold: number): number { 2 | 3 | } 4 | 5 | console.log(depositProfit(100, 20, 170)) -------------------------------------------------------------------------------- /differentSymbolsNaive/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-8/8N7p3MqzGQg5vFJfZ) 4 | --- 5 | Given a string, find the number of different characters in it. 6 | 7 | **Example** 8 | 9 | For s = "cabca", the output should be 10 | differentSymbolsNaive(s) = 3. 11 | 12 | There are 3 different characters a, b and c. 13 | 14 | **Hints** 15 | - includes() 16 | - split() 17 | - push() 18 | 19 | **Input/Output** 20 | 21 | - **[execution time limit] 4 seconds (js)** 22 | - **[input] string s** 23 | 24 | A string of lowercase English letters. 25 | 26 | *Guaranteed constraints:* 27 | 28 | 3 ≤ s.length ≤ 1000. 29 | 30 | - **[output] integer** -------------------------------------------------------------------------------- /differentSymbolsNaive/differentSymbolsNaive.ts: -------------------------------------------------------------------------------- 1 | function differentSymbolsNaive(s: string): number { 2 | 3 | } 4 | 5 | console.log(differentSymbolsNaive('cabca')); 6 | -------------------------------------------------------------------------------- /digitDegree/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-9/AACpNbZANCkhHWNs3) 4 | --- 5 | Let's define digit degree of some positive integer as the number of times we need to replace this number with the sum of its digits until we get to a one digit number. 6 | 7 | Given an integer, find its digit degree. 8 | 9 | **Example** 10 | 11 | - For n = 5, the output should be 12 | digitDegree(n) = 0; 13 | - For n = 100, the output should be 14 | digitDegree(n) = 1. 15 | 1 + 0 + 0 = 1. 16 | - For n = 91, the output should be 17 | digitDegree(n) = 2. 18 | 9 + 1 = 10 -> 1 + 0 = 1. 19 | 20 | **Hints** 21 | - toString() 22 | - parseInt() 23 | - split() 24 | - reduce() 25 | 26 | **Input/Output** 27 | 28 | - **[time limit] 4000ms (js)** 29 | 30 | - **[input] integer n** 31 | 32 | *Guaranteed constraints:* 33 | 34 | 5 ≤ n ≤ 109. 35 | 36 | - **[output] integer** -------------------------------------------------------------------------------- /digitDegree/digitDegree.ts: -------------------------------------------------------------------------------- 1 | function digitDegree(n: number): number { 2 | 3 | } 4 | 5 | console.log(digitDegree(5)); 6 | console.log(digitDegree(10)); 7 | console.log(digitDegree(91)); -------------------------------------------------------------------------------- /domainType/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/godaddy/RjJwsTCiF663krgSP) 4 | --- 5 | GoDaddy makes a lot of different top-level domains available to its customers. A top-level domain is one that goes directly after the last dot ('.') in the domain name, for example .com in example.com. To help the users choose from available domains, GoDaddy is introducing a new feature that shows the type of the chosen top-level domain. You have to implement this feature. 6 | To begin with, you want to write a function that labels the domains as "commercial", "organization", "network" or "information" for .com, .org, .net or .info respectively. 7 | For the given list of domains return the list of their labels. 8 | 9 | **Example** 10 | 11 | - For domains = ["en.wiki.org", "codefights.com", "happy.net", "code.info"], the output should be 12 | domainType(domains) = ["organization", "commercial", "network", "information"]. 13 | 14 | **Hints** 15 | - split() 16 | - push() 17 | 18 | **Input/Output** 19 | 20 | - **[execution time limit] 5 seconds (ts)** 21 | 22 | - **[input] array.string domains** 23 | A list of domains, where each domain contains at least one dot. It is guaranteed that each top-level domain of these domains belongs to one of the types described above. 24 | 25 | *Guaranteed constraints:* 26 | 27 | 4 ≤ domains.length ≤ 25, 28 | 5 ≤ domains[i].length ≤ 20. 29 | 30 | - **[output] array.string** 31 | The list of labels for the given domains. -------------------------------------------------------------------------------- /domainType/domainType.ts: -------------------------------------------------------------------------------- 1 | function domainType(domains: string[]): string[] { 2 | 3 | } 4 | 5 | console.log(domainType(["en.wiki.org", "codefights.com", "happy.net", "code.info"])); -------------------------------------------------------------------------------- /electionWinners/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/well-of-integration/8RiRRM3yvbuAd3MNg) 4 | --- 5 | Elections are in progress! 6 | 7 | Given an array of the numbers of votes given to each of the candidates so far, and an integer k equal to the number of voters who haven't cast their vote yet, find the number of candidates who still have a chance to win the election. 8 | 9 | The winner of the election must secure strictly more votes than any other candidate. If two or more candidates receive the same (maximum) number of votes, assume there is no winner at all. 10 | 11 | **Example** 12 | 13 | For votes = [2, 3, 5, 2] and k = 3, the output should be 14 | electionsWinners(votes, k) = 2. 15 | 16 | - The first candidate got 2 votes. Even if all of the remaining 3 candidates vote for him, he will still have only 5 votes, i.e. the same number as the third candidate, so there will be no winner. 17 | 18 | - The second candidate can win if all the remaining candidates vote for him (3 + 3 = 6 > 5). 19 | 20 | - The third candidate can win even if none of the remaining candidates vote for him. For example, if each of the remaining voters cast their votes for each of his opponents, he will still be the winner (the votes array will thus be [3, 4, 5, 3]). 21 | 22 | - The last candidate can't win no matter what (for the same reason as the first candidate). 23 | 24 | Thus, only 2 candidates can win (the second and the third), which is the answer. 25 | 26 | **Hints** 27 | - sort() 28 | - Math.max() 29 | 30 | **Input/Output** 31 | 32 | - **[execution time limit] 5 seconds (ts)** 33 | 34 | - **[input] array.integer votes** 35 | A non-empty array of non-negative integers. Its ith element denotes the number of votes cast for the ith candidate. 36 | 37 | *Guaranteed constraints:* 38 | 39 | 4 ≤ votes.length ≤ 105, 40 | 0 ≤ votes[i] ≤ 104. 41 | 42 | - **[input] integer k** 43 | The number of voters who haven't cast their vote yet. 44 | 45 | *Guaranteed constraints:* 46 | 0 ≤ k ≤ 105. 47 | 48 | - **[output] integer** -------------------------------------------------------------------------------- /electionWinners/electionWinners.ts: -------------------------------------------------------------------------------- 1 | function electionsWinners(votes: number[], k: number): number { 2 | 3 | } 4 | 5 | console.log(electionsWinners([2, 3, 5, 2], 3)); -------------------------------------------------------------------------------- /encloseInBrackets/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/book-market/K2ieDm98sPDzzMepz) 4 | --- 5 | Given a string, enclose it in round brackets. 6 | 7 | **Example** 8 | 9 | For inputString = "abacaba", the output should be 10 | encloseInBrackets(inputString) = "(abacaba)". 11 | 12 | **Input/Output** 13 | 14 | - **[execution time limit] 5 seconds (ts)** 15 | 16 | - **[input] string inputString** 17 | 18 | *Guaranteed constraints:* 19 | 20 | 0 ≤ inputString.length ≤ 10 21 | 22 | - **[output] string** 23 | -------------------------------------------------------------------------------- /encloseInBrackets/encloseInBrackets.ts: -------------------------------------------------------------------------------- 1 | function encloseInBrackets(inputString: string): string { 2 | 3 | } 4 | 5 | console.log(encloseInBrackets('abacaba')); -------------------------------------------------------------------------------- /evenDigitsOnly/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-6/6cmcmszJQr6GQzRwW) 4 | --- 5 | Check if all digits of the given integer are even. 6 | 7 | **Example** 8 | 9 | - For n = 248622, the output should be 10 | evenDigitsOnly(n) = true; 11 | - For n = 642386, the output should be 12 | evenDigitsOnly(n) = false. 13 | 14 | **Hints** 15 | - toString() 16 | - split() 17 | - every() 18 | - parseInt() 19 | 20 | **Input/Output** 21 | 22 | - **[time limit] 4000ms (js)** 23 | - **[input] integer n** 24 | 25 | *Guaranteed constraints:* 26 | 27 | 1 ≤ n ≤ 109. 28 | 29 | - **[output] boolean** 30 | 31 | true if all digits of n are even, false otherwise. -------------------------------------------------------------------------------- /evenDigitsOnly/evenDigitsOnly.ts: -------------------------------------------------------------------------------- 1 | function evenDigitsOnly(n: number): boolean { 2 | 3 | } 4 | 5 | console.log(evenDigitsOnly(248622)); 6 | console.log(evenDigitsOnly(642386)); -------------------------------------------------------------------------------- /extractEachKth/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-8/3AgqcKrxbwFhd3Z3R) 4 | --- 5 | Given array of integers, remove each kth element from it. 6 | 7 | **Example** 8 | 9 | For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be 10 | extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]. 11 | 12 | **Hints** 13 | - filter() 14 | 15 | **Input/Output** 16 | 17 | - **[execution time limit] 4 seconds (js)** 18 | - **[input] array.integer inputArray** 19 | 20 | *Guaranteed constraints:* 21 | 5 ≤ inputArray.length ≤ 15, 22 | -20 ≤ inputArray[i] ≤ 20. 23 | 24 | - **[input] integer k** 25 | 26 | *Guaranteed constraints:* 27 | 1 ≤ k ≤ 10. 28 | 29 | - **[output] array.integer** 30 | inputArray without elements k - 1, 2k - 1, 3k - 1 etc. -------------------------------------------------------------------------------- /extractEachKth/extractEachKth.ts: -------------------------------------------------------------------------------- 1 | function extractEachKth(inputArray:number[], k: number): number[] { 2 | } 3 | 4 | console.log(extractEachKth([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)); -------------------------------------------------------------------------------- /extractMatrixColumn/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/list-backwoods/zwXiykHLor6eKHaLY) 4 | --- 5 | Given a rectangular matrix and an integer column, return an array containing the elements of the columnth column of the given matrix (the leftmost column is the 0th one). 6 | 7 | **Example** 8 | 9 | For matrix = [[1, 1, 1, 2], 10 | [0, 5, 0, 4], 11 | [2, 1, 3, 6]] 12 | 13 | and column = 2, the output should be 14 | extractMatrixColumn(matrix, column) = [1, 0, 3]. 15 | 16 | **Hints** 17 | - push() 18 | 19 | **Input/Output** 20 | 21 | - **[execution time limit] 5 seconds (ts)** 22 | - **[input] array.array.integer matrix** 23 | 2-dimensional array of integers representing a rectangular matrix. 24 | 25 | *Guaranteed constraints:* 26 | 1 ≤ matrix.length ≤ 4, 27 | 1 ≤ matrix[0].length ≤ 4, 28 | 0 ≤ matrix[i][j] ≤ 300. 29 | 30 | - **[input] integer column** 31 | An integer not greater than the number of matrix columns. 32 | 33 | *Guaranteed constraints:* 34 | 0 ≤ column ≤ matrix[i].length - 1. 35 | 36 | - **[output] array.integer** 37 | -------------------------------------------------------------------------------- /extractMatrixColumn/extractMatrixColumn.ts: -------------------------------------------------------------------------------- 1 | function extractMatrixColumn(matrix: number[][], column: number): number[] { 2 | 3 | } 4 | 5 | console.log(extractMatrixColumn([[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]], 2)); -------------------------------------------------------------------------------- /factorializeANumber/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ### Check Out More Algorithms like this at FreeCodeCamp 4 | --- 5 | 6 | Return the factorial of the provided integer. 7 | 8 | If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n. 9 | 10 | Factorials are often represented with the shorthand notation n! 11 | 12 | For example: 5! = 1 * 2 * 3 * 4 * 5 = 120 13 | 14 | Only integers greater than or equal to zero will be supplied to the function. 15 | 16 | Remember to use Read-Search-Ask if you get stuck. Write your own code. 17 | 18 | **Example** 19 | - factorializeANumber(5) returns 120; 20 | - factorializeANumber(10) returns 3628800; -------------------------------------------------------------------------------- /factorializeANumber/factorializeANumber.ts: -------------------------------------------------------------------------------- 1 | function factorializeANumber(num: number): number { 2 | 3 | } 4 | 5 | console.log(factorializeANumber(5)); 6 | console.log(factorializeANumber(10)); -------------------------------------------------------------------------------- /fancyRide/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/uber/4c3qzzQg8Zg9AfLKH) 4 | --- 5 | Being a new Uber user, you have $20 off your first ride. You want to make the most out of it and drive in the fanciest car you can afford, without spending any out-of-pocket money. There are 5 options, from the least to the most expensive: "UberX", "UberXL", "UberPlus", "UberBlack" and "UberSUV". 6 | 7 | You know the length l of your ride in miles and how much one mile costs for each car. Find the best car you can afford. 8 | 9 | **Example** 10 | 11 | - For l = 30 and fares = [0.3, 0.5, 0.7, 1, 1.3], the output should be 12 | fancyRide(l, fares) = "UberXL". 13 | 14 | The cost for the ride in this car would be $15, which you can afford, but "UberPlus" would cost $21, which is too much for you. 15 | 16 | **Input/Output** 17 | 18 | - **[execution time limit] 5 seconds (ts)** 19 | 20 | - **[input] integer l 21 | 22 | A positive number representing the length of the ride. 23 | 24 | 25 | *Guaranteed constraints:* 26 | 27 | 4 ≤ l ≤ 30. 28 | 29 | - **[input] array.float fares** 30 | 31 | A strictly increasing array of 5 elements. fares[0] stands for dollars per mile in "UberX", fares[1] is the same for "UberXL", etc. 32 | 33 | *Guaranteed constraints:* 34 | 35 | 0.3 ≤ fares[i] ≤ 5.0. 36 | 37 | - **[output] string** 38 | 39 | The car that you should choose: "UberX", "UberXL", "UberPlus", "UberBlack" or "UberSUV". It is guaranteed that you can afford at least one of them. 40 | -------------------------------------------------------------------------------- /fancyRide/fancyRide.ts: -------------------------------------------------------------------------------- 1 | function fancyRide(l: number, fares: number[]): string { 2 | 3 | } 4 | 5 | console.log(fancyRide(30, [0.3, 0.5, 0.7, 1, 1.3])); -------------------------------------------------------------------------------- /fareEstimator/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/uber/HNQwGHfKAoYsz9KX6) 4 | --- 5 | Uber is building a Fare Estimator that can tell you how much your ride will cost before you request it. It works by passing approximated ride distance and ride time through this formula: 6 | 7 | (Cost per minute) * (ride time) + (Cost per mile) * (ride distance) 8 | 9 | where Cost per minute and Cost per mile depend on the car type. 10 | 11 | You are one of the engineers building the Fare Estimator, so knowing cost per minute and cost per mile for each car type, as well as ride distance and ride time, return the fare estimates for all car types. 12 | **Example** 13 | 14 | - For 15 | ride_time = 30, 16 | ride_distance = 7, 17 | cost_per_minute = [0.2, 0.35, 0.4, 0.45] and 18 | cost_per_mile = [1.1, 1.8, 2.3, 3.5], the output should be 19 | fareEstimator(ride_time, ride_distance, cost_per_minute, cost_per_mile) = [13.7, 23.1, 28.1, 38]. 20 | 21 | Since: 22 | 23 | 30 * 0.2 + 7 * 1.1 = 6 + 7.7 = 13.7 24 | 30 * 0.35 + 7 * 1.8 = 10.5 + 12.6 = 23.1 25 | 30 * 0.4 + 7 * 2.3 = 12 + 16.1 = 28.1 26 | 30 * 0.45 + 7 * 3.5 = 13.5 + 24.5 = 38 27 | 28 | **Hint** 29 | - push() 30 | 31 | **Input/Output** 32 | 33 | - **[execution time limit] 5 seconds (ts)** 34 | 35 | - **[input] integer ride_time** 36 | 37 | A positive integer, ride duration in minutes. 38 | 39 | *Guaranteed constraints:* 40 | 41 | 10 ≤ ride_time ≤ 50. 42 | 43 | - **[input] integer ride_distance** 44 | 45 | A positive integer, ride distance in miles. 46 | 47 | *Guaranteed constraints:* 48 | 49 | 5 ≤ ride_distance ≤ 20. 50 | 51 | **[input] array.float cost_per_minute** 52 | 53 | cost_per_minute[i] is a positive number denoting cost per minute for the ith car type. There are at least 4 car types in every city where Uber operates. 54 | 55 | *Guaranteed constraints:* 56 | 57 | 4 ≤ cost_per_minute.length ≤ 10, 58 | 0.1 ≤ cost_per_minute[i] ≤ 350.0. 59 | 60 | **[input] array.float cost_per_mile** 61 | 62 | cost_per_mile[i] is a positive number denoting cost per mile for the ith car type. It is guaranteed that cost_per_minute and cost_per_mile have the same number of elements. 63 | 64 | *Guaranteed constraints:* 65 | 66 | cost_per_mile.length = cost_per_minute.length, 67 | 0.5 ≤ cost_per_mile[i] ≤ 7.0. 68 | 69 | **[output] array.float** 70 | 71 | An array of estimated fares for each car type. -------------------------------------------------------------------------------- /fareEstimator/fareEstimator.ts: -------------------------------------------------------------------------------- 1 | function fareEstimator(ride_time: number, ride_distance: number, cost_per_minute: number[], cost_per_mile: number[]): number[] { 2 | 3 | } 4 | 5 | console.log(fareEstimator(30, 7, [0.2, 0.35, 0.4, 0.45], [1.1, 1.8, 2.3, 3.5])); 6 | -------------------------------------------------------------------------------- /fermactor/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/company-challenges/uber/HNQwGHfKAoYsz9KX6) 4 | --- 5 | Fermat's factorization method is: 6 | If a · b = n (where a ≤ b), then there exist some c and d such that n = c^2 - d^2. 7 | Your goal is to return for given n such c and d as an array. 8 | Since we want c and d to be uniquely determined, in all test cases n is a semiprime number. 9 | 10 | **Example** 11 | 12 | - For n = 15, the output should be 13 | fermactor(n) = [4, 1]. 14 | 15 = 4^2 - 1^2. 15 | 16 | **Hints** 17 | - Math.pow() 18 | 19 | **Input/Output** 20 | 21 | - **[execution time limit] 4 seconds (js)** 22 | 23 | - **[input] integer n** 24 | 25 | A semiprime number. 26 | 27 | *Guaranteed constraints:* 28 | 29 | 10 < n < 109. 30 | 31 | - **[output] array.integer** 32 | 33 | c and d are guaranteed to be integers if the difference between a and b is even. For all test cases, this is true. 34 | -------------------------------------------------------------------------------- /fermactor/fermactor.ts: -------------------------------------------------------------------------------- 1 | function fermactor(n: number): number[] { 2 | 3 | } 4 | 5 | console.log(fermactor(15)); -------------------------------------------------------------------------------- /findClosestPair/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/challenge/4Q22wFQPwR7zq2FS4) 4 | --- 5 | Given an array of integers numbers, we'd like to find the closest pair of elements that add up to sum. Return the distance between the closest pair (absolute difference between the two indices). If there isn't a pair that adds up to sum, return -1. 6 | 7 | **Example** 8 | 9 | - For numbers = [1, 0, 2, 4, 3, 0] and sum = 5 the output should be findClosestPair(numbers, sum) = 2. 1 and 4 have a sum of 5, but 2 and 3 are closer. 10 | 11 | - For numbers = [2, 3, 7] and sum = 8 the output should be findClosestPair(numbers, sum) = -1. There are no pairs that have a sum of 8. 12 | 13 | **Hints** 14 | - Math.abs() 15 | 16 | **Input/Output** 17 | 18 | - **[execution time limit] 5 seconds (ts)** 19 | 20 | - **[input] array.integer numbers** 21 | 22 | An array of integers. 23 | 24 | *Guaranteed constraints:* 25 | 26 | 2 ≤ numbers.length ≤ 3 · 105 27 | -1000 ≤ numbers[i] ≤ 1000 28 | 29 | - **[input] integer sum** 30 | 31 | An integer representing the sum of the pair we're looking for. 32 | 33 | *Guaranteed constraints:* 34 | 35 | -2000 ≤ sum ≤ 2000 36 | 37 | - **[output] integer** 38 | 39 | An integer representing the difference between the indices of the closest pair of elements that add up to sum (or -1 if there isn't one). 40 | -------------------------------------------------------------------------------- /findClosestPair/findClosestPair.ts: -------------------------------------------------------------------------------- 1 | function findClosestPair(numbers: number[], sum: number): number { 2 | 3 | } 4 | 5 | console.log(findClosestPair([1, 0, 2, 4, 3, 0], 5)); 6 | console.log(findClosestPair([2, 3, 7], 8)); -------------------------------------------------------------------------------- /findEmailDomain/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/book-market/TXFLopNcCNbJLQivP 4 | --- 5 | An email address such as "John.Smith@example.com" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com"). 6 | 7 | The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses. 8 | 9 | Given a valid email address, find its domain part. 10 | 11 | **Example** 12 | 13 | - For address = "prettyandsimple@example.com", the output should be 14 | findEmailDomain(address) = "example.com"; 15 | 16 | - For address = "<>[]:,;@\"!#$%&*+-/=?^_{}| ~.a\"@example.org", the output should be 17 | findEmailDomain(address) = "example.org". 18 | 19 | **Hints** 20 | - lastIndexOf() 21 | - slice() 22 | 23 | **Input/Output** 24 | 25 | - **[execution time limit] 5 seconds (ts)** 26 | 27 | - **[input] string address** 28 | 29 | *Guaranteed constraints:* 30 | 31 | 10 ≤ address.length ≤ 50. 32 | 33 | - **[output] string** 34 | 35 | -------------------------------------------------------------------------------- /findEmailDomain/findEmailDomain.ts: -------------------------------------------------------------------------------- 1 | function findEmailDomain(address: string): string { 2 | 3 | } 4 | 5 | console.log(findEmailDomain('prettyandsimple@example.com')); 6 | console.log(findEmailDomain('<>[]:,;@\"!#$%&*+-/=?^_{}| ~.a\"@example.org')); 7 | -------------------------------------------------------------------------------- /firstDigit/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-8/rRGGbTtwZe2mA8Wov) 4 | --- 5 | Find the leftmost digit that occurs in a given string. 6 | 7 | **Example** 8 | 9 | - For inputString = "var_1__Int", the output should be 10 | firstDigit(inputString) = '1'; 11 | 12 | - For inputString = "q2q-q", the output should be 13 | firstDigit(inputString) = '2'; 14 | 15 | - For inputString = "0ss", the output should be 16 | firstDigit(inputString) = '0'. 17 | 18 | **Hints** 19 | - split() 20 | - includes() 21 | 22 | **Input/Output** 23 | 24 | - **[execution time limit] 5 seconds (ts)** 25 | 26 | - **[input] string inputString** 27 | 28 | A string containing at least one digit. 29 | 30 | *Guaranteed constraints:* 31 | 32 | 3 ≤ inputString.length ≤ 10. 33 | 34 | - **[output] char** 35 | 36 | -------------------------------------------------------------------------------- /firstDigit/firstDigit.ts: -------------------------------------------------------------------------------- 1 | function firstDigit(inputString: string): string { 2 | 3 | } 4 | 5 | console.log(firstDigit('var_1__Int')); 6 | console.log(firstDigit('q2q-q')); 7 | console.log(firstDigit('0ss')); 8 | -------------------------------------------------------------------------------- /firstDuplicate/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/interview-practice/task/pMvymcahZ8dY4g75q) 4 | --- 5 | Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more than 1 duplicated numbers, return the number for which the second occurrence has a smaller index than the second occurrence of the other number does. If there are no such elements, return -1. 6 | 7 | **Example** 8 | 9 | - For a = [2, 1, 3, 5, 3, 2], the output should be 10 | firstDuplicate(a) = 3. 11 | 12 | There are 2 duplicates: numbers 2 and 3. The second occurrence of 3 has a smaller index than the second occurrence of 2 does, so the answer is 3. 13 | 14 | - For a = [2, 4, 3, 5, 1], the output should be 15 | firstDuplicate(a) = -1. 16 | 17 | **Hints** 18 | - hasOwnProperty() 19 | 20 | **Input/Output** 21 | 22 | - **[execution time limit] 5 seconds (ts)** 23 | 24 | - **[input] array.integer a** 25 | 26 | A string containing at least one digit. 27 | 28 | *Guaranteed constraints:* 29 | 30 | 1 ≤ a.length ≤ 105, 31 | 1 ≤ a[i] ≤ a.length. 32 | 33 | - **[output] integer** 34 | The element in a that occurs in the array more than once and has the minimal index for its second occurrence. If there are no such elements, return -1. 35 | 36 | -------------------------------------------------------------------------------- /firstDuplicate/firstDuplicate.ts: -------------------------------------------------------------------------------- 1 | function firstDuplicate(a: number[]): number { 2 | 3 | } 4 | 5 | console.log(firstDuplicate([2, 1, 3, 5, 3, 2])); 6 | console.log(firstDuplicate([2, 4, 3, 5, 1])); 7 | -------------------------------------------------------------------------------- /firstNotRepeatingCharacter/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/interview-practice/task/uX5iLwhc6L5ckSyNC) 4 | Note: Write a solution that only iterates over the string once and uses O(1) additional memory, since this is what you would be asked to do during a real interview. 5 | 6 | Given a string s, find and return the first instance of a non-repeating character in it. If there is no such character, return '_'. 7 | 8 | **Example** 9 | 10 | - For s = "abacabad", the output should be 11 | firstNotRepeatingCharacter(s) = 'c'. 12 | 13 | There are 2 non-repeating characters in the string: 'c' and 'd'. Return c since it appears in the string first. 14 | 15 | - For s = "abacabaabacaba", the output should be 16 | firstNotRepeatingCharacter(s) = '_'. 17 | 18 | There are no characters in this string that do not repeat. 19 | 20 | **Hints** 21 | - split() 22 | - hasOwnProperty() 23 | 24 | 25 | **Input/Output** 26 | 27 | - **[execution time limit] 5 seconds (ts)** 28 | 29 | - **[input] string s** 30 | A string that contains only lowercase English letters. 31 | 32 | *Guaranteed constraints:* 33 | 34 | 1 ≤ s.length ≤ 10^5. 35 | 36 | - **[output] char** 37 | The first non-repeating character in s, or '_' if there are no characters that do not repeat. 38 | 39 | -------------------------------------------------------------------------------- /firstNotRepeatingCharacter/firstNotRepeatingCharacter.ts: -------------------------------------------------------------------------------- 1 | function firstNotRepeatingCharacter(s: string): string { 2 | 3 | } 4 | 5 | console.log(firstNotRepeatingCharacter('abacabad')); 6 | console.log(firstNotRepeatingCharacter('abacabaabacaba')); 7 | -------------------------------------------------------------------------------- /flattenArray/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller) 2 | 3 | --- 4 | Flatten a nested array. You must account for varying levels of nesting. 5 | 6 | **Example** 7 | 8 | - steamrollArray([[["a"]], [["b"]]]) should return ["a", "b"]. 9 | 10 | - steamrollArray([1, [2], [3, [[4]]]]) should return [1, 2, 3, 4] 11 | 12 | **Hints** 13 | - isArray() 14 | - push() -------------------------------------------------------------------------------- /flattenArray/flattenArray.ts: -------------------------------------------------------------------------------- 1 | function flattenArray(arr: any[]): any[] { 2 | 3 | } 4 | 5 | console.log(flattenArray([[["a"]], [["b"]]])); 6 | console.log(flattenArray([1, [2], [3, [[4]]]])); 7 | -------------------------------------------------------------------------------- /growingPlant/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/intro/level-9/xHvruDnQCx7mYom3T) 4 | --- 5 | Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed meters due to the lack of sun heat. Initially, plant is 0 meters tall. We plant the seed at the beginning of a day. We want to know when the height of the plant will reach a certain level. 6 | 7 | **Example** 8 | 9 | For upSpeed = 100, downSpeed = 10 and desiredHeight = 910, the output should be 10 | growingPlant(upSpeed, downSpeed, desiredHeight) = 10. 11 | 12 | **Input/Output** 13 | 14 | - **[time limit] 4000ms (js)** 15 | - **[input] integer upSpeed** 16 | 17 | A positive integer representing the daily growth. 18 | 19 | *Guaranteed constraints:* 20 | 21 | 5 ≤ upSpeed ≤ 100. 22 | 23 | - **[input] integer downSpeed** 24 | 25 | A positive integer representing the nightly decline. 26 | 27 | *Guaranteed constraints:* 28 | 29 | 2 ≤ downSpeed < upSpeed. 30 | 31 | - **[input] integer desiredHeight** 32 | 33 | A positive integer representing the threshold. 34 | 35 | *Guaranteed constraints:* 36 | 37 | 4 ≤ desiredHeight ≤ 1000. 38 | 39 | - **[output] integer** 40 | 41 | The number of days that it will take for the plant to reach/pass desiredHeight (including the last day in the total count). -------------------------------------------------------------------------------- /growingPlant/growingPlant.ts: -------------------------------------------------------------------------------- 1 | function growingPlant(upSpeed: number, downSpeed: number, desiredHeight: number): number { 2 | 3 | } 4 | 5 | console.log(growingPlant(100, 10, 910)) -------------------------------------------------------------------------------- /houseNumbersSum/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/well-of-integration/3QMXNwGfvLMoQwed7) 4 | --- 5 | A boy is walking a long way from school to his home. To make the walk more fun he decides to add up all the numbers of the houses that he passes by during his walk. Unfortunately, not all of the houses have numbers written on them, and on top of that the boy is regularly taking turns to change streets, so the numbers don't appear to him in any particular order. 6 | 7 | At some point during the walk the boy encounters a house with number 0 written on it, which surprises him so much that he stops adding numbers to his total right after seeing that house. 8 | 9 | For the given sequence of houses determine the sum that the boy will get. It is guaranteed that there will always be at least one 0 house on the path. 10 | 11 | **Example** 12 | 13 | For inputArray = [5, 1, 2, 3, 0, 1, 5, 0, 2], the output should be 14 | houseNumbersSum(inputArray) = 11. 15 | 16 | The answer was obtained as 5 + 1 + 2 + 3 = 11. 17 | 18 | **Input/Output** 19 | 20 | - **[execution time limit] 5 seconds (ts)** 21 | - **[input] array.integer inputArray** 22 | 23 | *Guaranteed constraints:* 24 | 25 | 5 ≤ inputArray.length ≤ 10, 26 | 0 ≤ inputArray[i] ≤ 10. 27 | 28 | - **[output] integer** -------------------------------------------------------------------------------- /houseNumbersSum/houseNumbersSum.ts: -------------------------------------------------------------------------------- 1 | function houseNumbersSum(inputArray: number[]): number { 2 | 3 | } 4 | 5 | console.log(houseNumbersSum([5, 1, 2, 3, 0, 1, 5, 0, 2])); -------------------------------------------------------------------------------- /houseOfCats/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/well-of-integration/RaWLwT2eb96hp4N5Z) 4 | --- 5 | There are some people and cats in a house. You are given the number of legs they have all together. Your task is to return an array containing every possible number of people that could be in the house sorted in ascending order. It's guaranteed that each person has 2 legs and each cat has 4 legs. 6 | 7 | **Example** 8 | 9 | For legs = 6, the output should be 10 | houseOfCats(legs) = [1, 3]. 11 | 12 | There could be either 1 cat and 1 person (4 + 2 = 6) or 3 people (2 * 3 = 6). 13 | 14 | For legs = 2, the output should be 15 | houseOfCats(legs) = [1]. 16 | 17 | There can be only 1 person. 18 | 19 | **Hints** 20 | - unshift() 21 | - push() 22 | 23 | **Input/Output** 24 | 25 | - **[execution time limit] 5 seconds (ts)** 26 | - **[input] integer legs** 27 | 28 | The total number of legs in the house. 29 | 30 | *Guaranteed constraints:* 31 | 32 | 0 ≤ legs ≤ 45. 33 | 34 | - **[output] array.integer** 35 | 36 | Every possible number of people that can be in the house. 37 | 38 | -------------------------------------------------------------------------------- /houseOfCats/houseOfCats.ts: -------------------------------------------------------------------------------- 1 | function houseOfCats(legs: number): number[] { 2 | 3 | } 4 | 5 | console.log(houseOfCats(6)); 6 | console.log(houseOfCats(2)); 7 | -------------------------------------------------------------------------------- /htmlEndTagByStartTag/README.md: -------------------------------------------------------------------------------- 1 | ### Check Out My [YouTube Channel](https://www.YouTube.com/CodingTutorials360) 2 | 3 | ##### Algorithm Challenge Available At [CodeFights](https://codefights.com/arcade/code-arcade/book-market/MX94DWTrwQw2gLrTi) 4 | --- 5 | You are implementing your own HTML editor. To make it more comfortable for developers you would like to add an auto-completion feature to it. 6 | 7 | Given the starting HTML tag, find the appropriate end tag which your editor should propose. 8 | 9 | If you are not familiar with HTML, consult with this note. 10 | 11 | **Example** 12 | 13 | - For startTag = ""; 15 | 16 | - For startTag = "", the output should be 17 | htmlEndTagByStartTag(startTag) = "". 18 | 19 | **Hints** 20 | - split() 21 | - toString() 22 | 23 | **Input/Output** 24 | 25 | - **[execution time limit] 5 seconds (ts)** 26 | - **[input] string startTag** 27 | 28 | The total number of legs in the house. 29 | 30 | *Guaranteed constraints:* 31 | 32 | 3 ≤ startTag.length ≤ 75. 33 | 34 | - **[output] string** 35 | -------------------------------------------------------------------------------- /htmlEndTagByStartTag/htmlEndTagByStartTag.ts: -------------------------------------------------------------------------------- 1 | function htmlEndTagByStartTag(startTag: string): string { 2 | 3 | } 4 | 5 | console.log(htmlEndTagByStartTag("