├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── absoluteValuesSumMinization ├── README.md ├── absoluteValuesSumMinization.spec.ts └── absoluteValuesSumMinization.ts ├── add ├── README.md ├── add.spec.ts └── add.ts ├── addBorder ├── README.md ├── addBorder.spec.ts └── addBorder.ts ├── addTwoDigits ├── README.md ├── addTwoDigits.spec.ts └── addTwoDigits.ts ├── adjacentElementsProduct ├── README.md ├── adjacentElementsProduct.spec.ts └── adjacentElementsProduct.ts ├── allLongestStrings ├── README.md ├── allLongestStrings.spec.ts └── allLongestStrings.ts ├── almostIncreasingSequence ├── README.md ├── almostIncreasingSequence.spec.ts └── almostIncreasingSequence.ts ├── alphabetSubSequence ├── README.md ├── alphabetSubSequence.spec.ts └── alphabetSubSequence.ts ├── alphabeticShift ├── README.md ├── alphabeticShift.spec.ts └── alphabeticShift.ts ├── alternatingSums ├── README.md ├── alternatingSums.spec.ts └── alternatingSums.ts ├── areEquallyStrong ├── README.md ├── areEquallyStrong.spec.ts └── areEquallyStrong.ts ├── areSimilar ├── README.md ├── areSimilar.spec.ts └── areSimilar.ts ├── arrayChange ├── README.md ├── arrayChange.spec.ts └── arrayChange.ts ├── arrayConversion ├── README.md ├── arrayConversion.spec.ts └── arrayConversion.ts ├── arrayMaxConsecutiveSum ├── README.md ├── arrayMaxConsecutiveSum.spec.ts └── arrayMaxConsecutiveSum.ts ├── arrayMaximalAdjacentDifference ├── README.md ├── arrayMaximalAdjacentDifference.spec.ts └── arrayMaximalAdjacentDifference.ts ├── arrayPreviousLess ├── README.md ├── arrayPreviousLess.spec.ts └── arrayPreviousLess.ts ├── arrayReplace ├── README.md ├── arrayReplace.spec.ts └── arrayReplace.ts ├── avoidObstacles ├── README.md ├── avoidObstacles.spec.ts └── avoidObstacles.ts ├── babel.config.js ├── bishopAndPawn ├── README.md ├── bishopAndPawn.spec.ts └── bishopAndPawn.ts ├── boxBlur ├── README.md ├── boxBlur.spec.ts └── boxBlur.ts ├── candies ├── README.md ├── candies.spec.ts └── candies.ts ├── caseInsensitivePalimdrome ├── README.md ├── caseInsensitivePalindrome.spec.ts └── caseInsensitivePalindrome.ts ├── centuryFromYear ├── README.md ├── centuryFromYear.spec.ts └── centuryFromYear.ts ├── characterParity ├── README.md ├── characterParity.ts └── chracterParity.spec.ts ├── checkPalindrome ├── README.md ├── checkPalindrome.spec.ts └── checkPalindrome.ts ├── chessBoardCellColor ├── README.md ├── chessBoardCellColor.spec.ts └── chessBoardCellColor.ts ├── chunkyMonkey ├── README.md ├── chunkeyMonkey.spec.ts └── chunkyMonkey.ts ├── circleOfNumbers ├── README.md ├── circleOfNumbers.spec.ts └── circleOfNumbers.ts ├── commonCharacterCount ├── README.md ├── commonCharacterCount.spec.ts └── commonCharacterCount.ts ├── companyBotStrategy ├── README.md ├── companyBotStrategy.spec.ts └── companyBotStrategy.ts ├── compareIntegers ├── README.md ├── compareIntegers.spec.ts └── compareIntegers.ts ├── composeRanges ├── README.md ├── composeRanges.spec.ts └── composeRanges.ts ├── confirmEnding ├── README.md ├── confirmEnding.ts └── confrimEnding.spec.ts ├── containsCloseNums ├── README.md ├── containsCloseNums.spec.ts └── containsCloseNums.ts ├── containsDuplicates ├── README.md ├── containsDuplicates.spec.ts └── containsDuplicates.ts ├── convertCelsiusToFahrenheit ├── README.md ├── convertCelsiusToFahrenheit.spec.ts └── convertCelsiusToFahrenheit.ts ├── convertString ├── README.md ├── convertString.spec.ts └── convertString.ts ├── crossingSum ├── README.md ├── crossingSum.spec.ts └── crossingSum.ts ├── depositProfit ├── README.md ├── depositProfit.spec.ts └── depositProfit.ts ├── differentSymbolsNaive ├── README.md ├── differentSymbolsNaive.spec.ts └── differentSymbolsNaive.ts ├── digitDegree ├── README.md ├── digitDegree.spec.ts └── digitDegree.ts ├── domainType ├── README.md ├── domainType.spec.ts └── domainType.ts ├── electionWinners ├── README.md ├── electionWinners.spec.ts └── electionWinners.ts ├── encloseInBrackets ├── README.md ├── encloseInBrackets.spec.ts └── encloseInBrackets.ts ├── evenDigitsOnly ├── README.md ├── evenDigitsOnly.spec.ts └── evenDigitsOnly.ts ├── extractEachKth ├── README.md ├── extractEachKth.spec.ts └── extractEachKth.ts ├── extractMatrixColumn ├── README.md ├── extractMatrixColumn.spec.ts └── extractMatrixColumn.ts ├── factorializeANumber ├── README.md ├── factorializeANumber.spec.ts └── factorializeANumber.ts ├── fancyRide ├── README.md ├── fancyRide.spec.ts └── fancyRide.ts ├── fareEstimator ├── README.md ├── fareEstimator.spec.ts └── fareEstimator.ts ├── fermactor ├── README.md ├── fermactor.spec.ts └── fermactor.ts ├── findClosestPair ├── README.md ├── findCloserPair.spec.ts └── findClosestPair.ts ├── findEmailDomain ├── README.md ├── findEmailDomain.spec.ts └── findEmailDomain.ts ├── firstDigit ├── README.md ├── firstDigit.spec.ts └── firstDigit.ts ├── firstDuplicate ├── README.md ├── firstDuplicate.spec.ts └── firstDuplicate.ts ├── firstNotRepeatingCharacter ├── README.md ├── firstNotRepeatingCharacter.spec.ts └── firstNotRepeatingCharacter.ts ├── flattenArray ├── README.md ├── flattenArray.spec.ts └── flattenArray.ts ├── growingPlant ├── README.md ├── growingPlant.spec.ts └── growingPlant.ts ├── houseNumbersSum ├── README.md ├── houseNumberSum.spec.ts └── houseNumbersSum.ts ├── houseOfCats ├── README.md ├── houseOfCats.spec.ts └── houseOfCats.ts ├── htmlEndTagByStartTag ├── README.md ├── htmlEndTagByStartTag.spec.ts └── htmlEndTagByStartTag.ts ├── incorrectPasswordAttempts ├── README.md ├── incorrectPasswordAttempts.spec.ts └── incorrectPasswordAttempts.ts ├── incrementalBackups ├── README.md ├── incrementalBackups.spec.ts └── incrementalBackups.ts ├── integerToStringOfFixedWidth ├── README.md ├── integerToStringOfFixedWidth.spec.ts └── integerToStringOfFixedWidth.ts ├── isLucky ├── README.md ├── isLucky.spec.ts └── isLucky.ts ├── isTandemRepeat ├── README.md ├── isTandemRepeat.spec.ts └── isTandemRepeat.ts ├── jest.config.ts ├── largestNumber ├── README.md ├── largestNumber.spec.ts └── largestNumber.ts ├── largestOfFour ├── README.md ├── largestOfFour.spec.ts └── largestOfFour.ts ├── lateRide ├── README.md ├── lateRide.spec.ts └── lateRide.ts ├── launchSequenceChecker ├── README.md ├── launchSequenceChecker.spec.ts └── launchSequenceChecker.ts ├── longestDigitsPrefix ├── README.md ├── longestDigitsPrefix.spec.ts └── longestDigitsPrefix.ts ├── makeArrayConsecutive2 ├── README.md ├── makeArrayConsecutive2.spec.ts └── makeArrayConsecutive2.ts ├── matrixElementsSum ├── README.md ├── matrixElementsSum.spec.ts └── matrixElementsSum.ts ├── maxMultiple ├── README.md ├── maxMultiple.spec.ts └── maxMultiple.ts ├── mineSweeper ├── README.md ├── mineSweeper.spec.ts └── mineSweeper.ts ├── minimalNumberOfCoins ├── README.md ├── minimalNumberOfCoins.spec.ts └── minimalNumberOfCoins.ts ├── missingLetters ├── README.md ├── missingLetters.spec.ts └── missingLetters.ts ├── mostFrequentDigitSum ├── README.md ├── mostFrequentDigitSum.spec.ts └── mostFrequentDigitSum.ts ├── newNumeralSystem ├── README.md ├── newNumeralSystem.spec.ts └── newNumeralSystem.ts ├── package-lock.json ├── package.json ├── pagesNumberingWithInk ├── README.md ├── pageNumberingWithInk.spec.ts └── pagesNumberingWithInk.ts ├── palindromeRearranging ├── README.md ├── palindromeRearranging.spec.ts └── palindromeRearranging.ts ├── pigLatin ├── README.md ├── pigLatin.spec.ts └── pigLatin.ts ├── proCategorization ├── README.md ├── proCategorization.spec.ts └── proCategorization.ts ├── properNounCorrection ├── README.md ├── properNounCorrection.spec.ts └── properNounCorrection.ts ├── ratingThreshold ├── README.md ├── ratingThreshold.spec.ts └── ratingThreshold.ts ├── reflectString ├── README.md ├── reflectString.spec.ts └── reflectString.ts ├── reverseAString ├── README.md ├── reverseAString.spec.ts └── reverseAString.ts ├── seatsInTheater ├── README.md ├── seatsInTheater.spec.ts └── seatsInTheater.ts ├── seekAndDestroy ├── README.md ├── seekAndDestroy.spec.ts └── seekAndDestroy.ts ├── shapeArea ├── README.md ├── shapeArea.spec.ts └── shapeArea.ts ├── sortByHeight ├── README.md ├── sortByHeight.spec.ts └── sortByHeight.ts ├── sortByLength ├── README.md ├── sortByLength.spec.ts └── sortByLength.ts ├── squareDigitsSequence ├── README.md ├── squareDigitsSequence.spec.ts └── squareDigitsSequence.ts ├── stolenLunch ├── README.md ├── stolenLunch.spec.ts └── stolenLunch.ts ├── stringsConstruction ├── README.md ├── stringsConstruction.spec.ts └── stringsConstruction.ts ├── sumAllPrimes ├── README.md ├── sumAllPrimes.spec.ts └── sumAllPrimes.ts ├── sumOddFibonacciNums ├── README.md ├── sumOddFibonacciNums.spec.ts └── sumOddFibonacciNums.ts ├── sumOfTwo ├── README.md ├── sumOfTwo.spec.ts └── sumOfTwo.ts ├── switchLights ├── README.md ├── switchLights.spec.ts └── switchLights.ts ├── tasksType ├── README.md ├── taskType.spec.ts └── tasksType.ts ├── tsconfig.json ├── uniqueDigitProducts ├── README.md ├── uniqueDigitsProducts.spec.ts └── uniqueDigitsProducts.ts └── validTime ├── README.md ├── validTime.spec.ts └── validTime.ts /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: CodingTutorials360 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['http://paypal.me/dylanisrael'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Check Out My YouTube Channel 2 | 3 | # 100AlgorithmsChallenge 4 | 5 | Check Out The 100 Algorithm's Challenge Course 6 | 7 |
This is the setup for my Udemy Course: The 100 Algorithms Challenge: How to Ace the JavaScript Coding Interview.
8 |There are 100 algorithms with README instructions as well as the initial function setup with a few test cases.
9 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { absoluteValuesSumMinimization } from './absoluteValuesSumMinization'; 2 | 3 | xdescribe(absoluteValuesSumMinimization.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [2, 4, 7]; 7 | 8 | // act 9 | const response = absoluteValuesSumMinimization(data); 10 | 11 | // assert 12 | expect(response).toBe(4); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [2, 4, 7, 6]; 18 | 19 | // act 20 | const response = absoluteValuesSumMinimization(data); 21 | 22 | // assert 23 | expect(response).toBe(4); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const data = [2, 4, 7, 6, 6]; 29 | 30 | // act 31 | const response = absoluteValuesSumMinimization(data); 32 | 33 | // assert 34 | expect(response).toBe(7); 35 | }); 36 | 37 | it('Test 4', () => { 38 | // arrange 39 | const data = [2, 4, 7, 6, 6, 8]; 40 | 41 | // act 42 | const response = absoluteValuesSumMinimization(data); 43 | 44 | // assert 45 | expect(response).toBe(7); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /absoluteValuesSumMinization/absoluteValuesSumMinization.ts: -------------------------------------------------------------------------------- 1 | export function absoluteValuesSumMinimization(a: number[]): number { 2 | return 5; 3 | } 4 | 5 | // console.log(absoluteValuesSumMinimization([2, 4, 7])); 6 | // console.log(absoluteValuesSumMinimization([2, 4, 7, 6])); 7 | // console.log(absoluteValuesSumMinimization([2, 4, 7, 6, 6])); 8 | // 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { add, add2 } from './add'; 2 | 3 | xdescribe(add.name, () => { 4 | it('test 1', () => { 5 | // act 6 | const result = add(1, 2); 7 | 8 | // assert 9 | expect(result).toBe(3); 10 | }); 11 | 12 | it('test 2', () => { 13 | // act 14 | const result = add(3, 2); 15 | 16 | // assert 17 | expect(result).toBe(5); 18 | }); 19 | }); 20 | 21 | xdescribe(add2.name, () => { 22 | // console.log(add2(2,3)); 23 | it('test 1', () => { 24 | // arrange 25 | const data = [1, 2, 3, 4, 5]; 26 | 27 | // act 28 | const result = add2(...data); 29 | 30 | // assert 31 | expect(result).toBe(15); 32 | }); 33 | 34 | it('test 2', () => { 35 | // arrange 36 | const data = [2, 3]; 37 | 38 | // act 39 | const result = add2(...data); 40 | 41 | // assert 42 | expect(result).toBe(5); 43 | }); 44 | }); -------------------------------------------------------------------------------- /add/add.ts: -------------------------------------------------------------------------------- 1 | export function add(param1: number, param2: number): number { 2 | 3 | } 4 | 5 | export function add2(...param1: number[]): number { 6 | 7 | } 8 | // console.log(add(1, 2)); 9 | // console.log(add(3, 2)); 10 | 11 | // console.log(add2(1,2,3,4,5)); 12 | // console.log(add2(2,3)); 13 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { addBorder } from './addBorder'; 2 | 3 | xdescribe(addBorder.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = ['abc, ded']; 7 | 8 | // act 9 | const response = addBorder(data); 10 | 11 | // assert 12 | expect(response).toEqual([ 13 | "*****", 14 | "*abc*", 15 | "*ded*", 16 | "*****" 17 | ]); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /addBorder/addBorder.ts: -------------------------------------------------------------------------------- 1 | export function addBorder(picture: string[]): string[] { 2 | 3 | } 4 | 5 | // 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { addTwoDigits } from './addTwoDigits'; 2 | 3 | xdescribe(addTwoDigits.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 29; 7 | 8 | // act 9 | const response = addTwoDigits(data); 10 | 11 | // assert 12 | expect(response).toBe(11); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /addTwoDigits/addTwoDigits.ts: -------------------------------------------------------------------------------- 1 | export function addTwoDigits(n: any): number { 2 | 3 | } 4 | 5 | // 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { adjacentElementsProduct } from './adjacentElementsProduct'; 2 | 3 | xdescribe(adjacentElementsProduct.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [3, 6, -2, -5, 7, 3]; 7 | 8 | // act 9 | const response = adjacentElementsProduct(data); 10 | 11 | // assert 12 | expect(response).toBe(21); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /adjacentElementsProduct/adjacentElementsProduct.ts: -------------------------------------------------------------------------------- 1 | export function adjacentElementsProduct(inputArray: number[]): number { 2 | 3 | } 4 | 5 | //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.spec.ts: -------------------------------------------------------------------------------- 1 | import { allLongestStrings } from './allLongestStrings'; 2 | 3 | xdescribe(allLongestStrings.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = ["aba", "aa", "ad", "vcd", "aba"]; 7 | 8 | // act 9 | const response = allLongestStrings(data); 10 | 11 | // assert 12 | expect(response).toEqual(["aba", "vcd", "aba"]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /allLongestStrings/allLongestStrings.ts: -------------------------------------------------------------------------------- 1 | export function allLongestStrings(inputArray: string[]): string[] { 2 | 3 | } 4 | 5 | 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { almostIncreasingSequence } from './almostIncreasingSequence'; 2 | 3 | xdescribe(almostIncreasingSequence.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [1, 3, 2, 1]; 7 | 8 | // act 9 | const response = almostIncreasingSequence(data); 10 | 11 | // assert 12 | expect(response).toBe(false); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [1, 3, 2]; 18 | 19 | // act 20 | const response = almostIncreasingSequence(data); 21 | 22 | // assert 23 | expect(response).toBe(true); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /almostIncreasingSequence/almostIncreasingSequence.ts: -------------------------------------------------------------------------------- 1 | export function almostIncreasingSequence(sequence: number[]): boolean { 2 | 3 | } 4 | 5 | // console.log(almostIncreasingSequence([1, 3, 2, 1])) 6 | // 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 | - split() 18 | 19 | **Input/Output** 20 | 21 | - **[execution time limit] 5 seconds (ts)** 22 | - **[input] string s** 23 | 24 | *Guaranteed constraints:* 25 | 26 | 2 ≤ s.length ≤ 15. 27 | 28 | **[output] boolean** 29 | 30 | true if the given string is a subsequence of the alphabet, false otherwise. 31 | -------------------------------------------------------------------------------- /alphabetSubSequence/alphabetSubSequence.spec.ts: -------------------------------------------------------------------------------- 1 | import { alphabetSubsequence } from './alphabetSubsequence'; 2 | 3 | xdescribe(alphabetSubsequence.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 'effg'; 7 | 8 | // act 9 | const response = alphabetSubsequence(data); 10 | 11 | // assert 12 | expect(response).toBe(false); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 'ace'; 18 | 19 | // act 20 | const response = alphabetSubsequence(data); 21 | 22 | // assert 23 | expect(response).toBe(true); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /alphabetSubSequence/alphabetSubSequence.ts: -------------------------------------------------------------------------------- 1 | export function alphabetSubsequence(s: string): boolean { 2 | 3 | } 4 | 5 | console.log(alphabetSubsequence('zab')) 6 | console.log(alphabetSubsequence('effg')) 7 | console.log(alphabetSubsequence('cdce')) 8 | console.log(alphabetSubsequence('ace')) 9 | console.log(alphabetSubsequence('bxz')) 10 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { alphabeticShift } from './alphabeticShift'; 2 | 3 | xdescribe(alphabeticShift.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 'crazy'; 7 | 8 | // act 9 | const response = alphabeticShift(data); 10 | 11 | // assert 12 | expect(response).toBe('dsbaz'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /alphabeticShift/alphabeticShift.ts: -------------------------------------------------------------------------------- 1 | export function alphabeticShift(inputString: string): string { 2 | 3 | } 4 | 5 | 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { alternatingSums } from './alternatingSums'; 2 | 3 | xdescribe(alternatingSums.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [50, 60, 60, 45, 70]; 7 | 8 | // act 9 | const response = alternatingSums(data); 10 | 11 | // assert 12 | expect(response).toEqual([180, 105]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /alternatingSums/alternatingSums.ts: -------------------------------------------------------------------------------- 1 | export function alternatingSums(a: number[]): number[] { 2 | 3 | } 4 | 5 | console.log(alternatingSums([50, 60, 60, 45, 70])) -------------------------------------------------------------------------------- /areEquallyStrong/areEquallyStrong.spec.ts: -------------------------------------------------------------------------------- 1 | import { areEquallyStrong } from './areEquallyStrong'; 2 | 3 | xdescribe(areEquallyStrong.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const yourLeft = 10; 7 | const yourRight = 15; 8 | const friendsLeft = 15; 9 | const friendsRight = 10; 10 | 11 | // act 12 | const response = areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight); 13 | 14 | // assert 15 | expect(response).toEqual(true); 16 | }); 17 | 18 | it('Test 2', () => { 19 | // arrange 20 | const yourLeft = 15; 21 | const yourRight = 10; 22 | const friendsLeft = 15; 23 | const friendsRight = 10; 24 | 25 | // act 26 | const response = areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight); 27 | 28 | // assert 29 | expect(response).toEqual(true); 30 | }); 31 | 32 | it('Test 3', () => { 33 | // arrange 34 | const yourLeft = 15; 35 | const yourRight = 10; 36 | const friendsLeft = 15; 37 | const friendsRight = 9; 38 | 39 | // act 40 | const response = areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight); 41 | 42 | // assert 43 | expect(response).toEqual(false); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /areEquallyStrong/areEquallyStrong.ts: -------------------------------------------------------------------------------- 1 | export function areEquallyStrong(yourLeft: number, yourRight: number, friendsLeft: number, friendsRight: number): boolean { 2 | 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { areSimilar } from './areSimilar'; 2 | 3 | xdescribe(areSimilar.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data1 = [1, 2, 3]; 7 | const data2 = [1, 2, 3]; 8 | 9 | // act 10 | const response = areSimilar(data1, data2); 11 | 12 | // assert 13 | expect(response).toEqual(true); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const data1 = [1, 2, 3]; 19 | const data2 = [2, 1, 3]; 20 | 21 | // act 22 | const response = areSimilar(data1, data2); 23 | 24 | // assert 25 | expect(response).toEqual(true); 26 | }); 27 | 28 | it('Test 3', () => { 29 | // arrange 30 | const data1 = [1, 2, 2]; 31 | const data2 = [2, 1, 1]; 32 | 33 | // act 34 | const response = areSimilar(data1, data2); 35 | 36 | // assert 37 | expect(response).toEqual(false); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /areSimilar/areSimilar.ts: -------------------------------------------------------------------------------- 1 | export function areSimilar(a: number[], b: number[]): boolean { 2 | 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayChange } from './arrayChange'; 2 | 3 | xdescribe(arrayChange.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [1, 1, 1]; 7 | 8 | // act 9 | const response = arrayChange(data); 10 | 11 | // assert 12 | expect(response).toBe(3); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /arrayChange/arrayChange.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayConversion } from './arrayConversion'; 2 | 3 | xdescribe(arrayConversion.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [1, 2, 3, 4, 5, 6, 7, 8]; 7 | 8 | // act 9 | const response = arrayConversion(data); 10 | 11 | // assert 12 | expect(response).toBe(186); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /arrayConversion/arrayConversion.ts: -------------------------------------------------------------------------------- 1 | export function arrayConversion(inputArray: number[]): number { 2 | 3 | } 4 | 5 | // console.log(arrayConversion([1, 2, 3, 4, 5, 6, 7, 8])); 6 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayMaxConsecutiveSum } from './arrayMaxConsecutiveSum'; 2 | 3 | xdescribe(arrayMaxConsecutiveSum.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [2, 3, 5, 1, 6]; 7 | const count = 2; 8 | 9 | // act 10 | const response = arrayMaxConsecutiveSum(data, count); 11 | 12 | // assert 13 | expect(response).toBe(8); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /arrayMaxConsecutiveSum/arrayMaxConsecutiveSum.ts: -------------------------------------------------------------------------------- 1 | export 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 | [](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 | For inputArray = [2, 9, 1, 0], the output should be 14 | arrayMaximalAdjacentDifference(inputArray) = 8. 15 | 16 | **Hints** 17 | - Math.abs() 18 | 19 | **Input/Output** 20 | 21 | - **[time limit] 4000ms (js)** 22 | - **[input] array.integer inputArray** 23 | 24 | *Guaranteed constraints:* 25 | 26 | 3 ≤ inputArray.length ≤ 10, 27 | 28 | -15 ≤ inputArray[i] ≤ 15. 29 | 30 | - **[output] integer** 31 | 32 | The maximal absolute difference. 33 | -------------------------------------------------------------------------------- /arrayMaximalAdjacentDifference/arrayMaximalAdjacentDifference.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayMaximalAdjacentDifference } from './arrayMaximalAdjacentDifference'; 2 | 3 | xdescribe(arrayMaximalAdjacentDifference.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [2, 4, 1, 0]; 7 | 8 | // act 9 | const response = arrayMaximalAdjacentDifference(data); 10 | 11 | // assert 12 | expect(response).toBe(3); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [2, 9, 1, 0]; 18 | 19 | // act 20 | const response = arrayMaximalAdjacentDifference(data); 21 | 22 | // assert 23 | expect(response).toBe(8); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /arrayMaximalAdjacentDifference/arrayMaximalAdjacentDifference.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayPreviousLess } from './arrayPreviousLess'; 2 | 3 | xdescribe(arrayPreviousLess.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [3, 5, 2, 4, 5]; 7 | 8 | // act 9 | const response = arrayPreviousLess(data); 10 | 11 | // assert 12 | expect(response).toEqual([-1, 3, -1, 2, 4]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /arrayPreviousLess/arrayPreviousLess.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayReplace } from './arrayReplace'; 2 | 3 | xdescribe(arrayReplace.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [3, 5, 2, 4, 5]; 7 | const elementToReplace = 1; 8 | const substitutionElement = 3; 9 | 10 | // act 11 | const response = arrayReplace(data, elementToReplace, substitutionElement); 12 | 13 | // assert 14 | expect(response).toEqual([3, 2, 3]); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /arrayReplace/arrayReplace.ts: -------------------------------------------------------------------------------- 1 | export 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 | **Hints** 18 | - sort() 19 | - every() 20 | 21 | **Input/Output** 22 | 23 | - **[time limit] 4000ms (js)** 24 | - **[input] array.integer inputArray** 25 | 26 | Non-empty array of positive integers. 27 | 28 | *Guaranteed constraints:* 29 | 30 | 2 ≤ inputArray.length ≤ 10, 31 | 32 | 1 ≤ inputArray[i] ≤ 40. 33 | 34 | - **[output] integer** 35 | 36 | The desired length. 37 | -------------------------------------------------------------------------------- /avoidObstacles/avoidObstacles.spec.ts: -------------------------------------------------------------------------------- 1 | import { avoidObstacles } from './avoidObstacles'; 2 | 3 | xdescribe(avoidObstacles.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [5, 3, 6, 7, 9]; 7 | 8 | 9 | // act 10 | const response = avoidObstacles(data); 11 | 12 | // assert 13 | expect(response).toBe(4); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /avoidObstacles/avoidObstacles.ts: -------------------------------------------------------------------------------- 1 | export function avoidObstacles(inputArray: number[]): number { 2 | 3 | } 4 | 5 | // console.log(avoidObstacles([5, 3, 6, 7, 9])); -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/preset-env', 5 | { 6 | targets: { 7 | node: 'current', 8 | }, 9 | }, 10 | ], 11 | '@babel/preset-typescript', 12 | ], 13 | }; -------------------------------------------------------------------------------- /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 |  10 | 11 | **Example** 12 | 13 | - For bishop = "a1" and pawn = "c3", the output should be 14 | bishopAndPawn(bishop, pawn) = true. 15 | 16 |  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.spec.ts: -------------------------------------------------------------------------------- 1 | import { bishopAndPawn } from './bishopAndPawn'; 2 | 3 | xdescribe(bishopAndPawn.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const position1 = 'a1'; 7 | const position2 = 'c3'; 8 | 9 | // act 10 | const response = bishopAndPawn(position1, position2); 11 | 12 | // assert 13 | expect(response).toBe(true); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /bishopAndPawn/bishopAndPawn.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { boxBlur } from './boxBlur'; 2 | 3 | xdescribe(boxBlur.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [[1, 1, 1], 7 | [1, 7, 1], 8 | [1, 1, 1]]; 9 | 10 | // act 11 | const response = boxBlur(data); 12 | 13 | // assert 14 | expect(response).toEqual([[1]]); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /boxBlur/boxBlur.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { candies } from './candies'; 2 | 3 | xdescribe(candies.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const n = 3; 7 | const m = 9; 8 | 9 | // act 10 | const response = candies(n, m); 11 | 12 | // assert 13 | expect(response).toBe(9); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /candies/candies.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { isCaseInsensitivePalindrome } from './caseInsensitivePalindrome'; 2 | 3 | xdescribe(isCaseInsensitivePalindrome.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 'AaBaa'; 7 | 8 | // act 9 | const response = isCaseInsensitivePalindrome(data); 10 | 11 | // assert 12 | expect(response).toBe(true); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 'abac'; 18 | 19 | // act 20 | const response = isCaseInsensitivePalindrome(data); 21 | 22 | // assert 23 | expect(response).toBe(false); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /caseInsensitivePalimdrome/caseInsensitivePalindrome.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { centuryFromYear } from './centuryFromYear'; 2 | 3 | xdescribe(centuryFromYear.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 1905; 7 | 8 | // act 9 | const response = centuryFromYear(data); 10 | 11 | // assert 12 | expect(response).toBe(20); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 1700; 18 | 19 | // act 20 | const response = centuryFromYear(data); 21 | 22 | // assert 23 | expect(response).toBe(17); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /centuryFromYear/centuryFromYear.ts: -------------------------------------------------------------------------------- 1 | export 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 | export function characterParity(symbol: string): string { 2 | 3 | } 4 | 5 | // console.log(characterParity('5')) 6 | // console.log(characterParity('8')) 7 | // console.log(characterParity('q')) 8 | -------------------------------------------------------------------------------- /characterParity/chracterParity.spec.ts: -------------------------------------------------------------------------------- 1 | import { characterParity } from './characterParity'; 2 | 3 | xdescribe(characterParity.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = '5'; 7 | 8 | // act 9 | const response = characterParity(data); 10 | 11 | // assert 12 | expect(response).toBe('odd'); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = '8'; 18 | 19 | // act 20 | const response = characterParity(data); 21 | 22 | // assert 23 | expect(response).toBe('even'); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const data = 'q'; 29 | 30 | // act 31 | const response = characterParity(data); 32 | 33 | // assert 34 | expect(response).toBe('not a digit'); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { checkPalindrome } from './checkPalindrome'; 2 | 3 | xdescribe(checkPalindrome.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 'aabaa'; 7 | 8 | // act 9 | const response = checkPalindrome(data); 10 | 11 | // assert 12 | expect(response).toBe(true); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 'abac'; 18 | 19 | // act 20 | const response = checkPalindrome(data); 21 | 22 | // assert 23 | expect(response).toBe(false); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const data = 'a'; 29 | 30 | // act 31 | const response = checkPalindrome(data); 32 | 33 | // assert 34 | expect(response).toBe(true); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /checkPalindrome/checkPalindrome.ts: -------------------------------------------------------------------------------- 1 | export 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 | ; 13 | 14 | - For cell1 = "A1" and cell2 = "H3", the output should be 15 | chessBoardCellColor(cell1, cell2) = false. 16 | 17 |  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.spec.ts: -------------------------------------------------------------------------------- 1 | import { chessBoardCellColor } from './chessBoardCellColor'; 2 | 3 | xdescribe(chessBoardCellColor.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const cell1 = 'A1'; 7 | const cell2 = 'C3'; 8 | 9 | // act 10 | const response = chessBoardCellColor(cell1, cell2); 11 | 12 | // assert 13 | expect(response).toBe(true); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const cell1 = 'A1'; 19 | const cell2 = 'H3'; 20 | 21 | // act 22 | const response = chessBoardCellColor(cell1, cell2); 23 | 24 | // assert 25 | expect(response).toBe(false); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /chessBoardCellColor/chessBoardCellColor.ts: -------------------------------------------------------------------------------- 1 | export 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/chunkeyMonkey.spec.ts: -------------------------------------------------------------------------------- 1 | import { chunkyMonkey } from './chunkyMonkey'; 2 | 3 | xdescribe(chunkyMonkey.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = ['a', 'b', 'c', 'd']; 7 | const length = 2; 8 | 9 | // act 10 | const response = chunkyMonkey(data, length); 11 | 12 | // assert 13 | expect(response).toEqual([["a", "b"], ["c", "d"]]); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const data = [0, 1, 2, 3, 4, 5]; 19 | const length = 4; 20 | 21 | // act 22 | const response = chunkyMonkey(data, length); 23 | 24 | // assert 25 | expect(response).toEqual([[0, 1, 2, 3], [4, 5]]); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /chunkyMonkey/chunkyMonkey.ts: -------------------------------------------------------------------------------- 1 | export 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 |  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.spec.ts: -------------------------------------------------------------------------------- 1 | import { circleOfNumbers } from './circleOfNumbers'; 2 | 3 | xdescribe(circleOfNumbers.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const n = 10; 7 | const firstNumber = 2; 8 | 9 | // act 10 | const response = circleOfNumbers(n, firstNumber); 11 | 12 | // assert 13 | expect(response).toBe(7); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /circleOfNumbers/circleOfNumbers.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { commonCharacterCount } from './commonCharacterCount'; 2 | 3 | xdescribe(commonCharacterCount.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const s1 = 'aabcc'; 7 | const s2 = 'adcaa'; 8 | 9 | // act 10 | const response = commonCharacterCount(s1, s2); 11 | 12 | // assert 13 | expect(response).toBe(3); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /commonCharacterCount/commonCharacterCount.ts: -------------------------------------------------------------------------------- 1 | export function commonCharacterCount(s1: string, s2: string): number { 2 | 3 | } 4 | 5 | // console.log(commonCharacterCount('aabcc', 'adcaa')); -------------------------------------------------------------------------------- /companyBotStrategy/companyBotStrategy.spec.ts: -------------------------------------------------------------------------------- 1 | import { companyBotStrategy } from './companyBotStrategy'; 2 | 3 | xdescribe(companyBotStrategy.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [[3, 1], [6, 1], [4, 1], [5, 1]]; 7 | 8 | // act 9 | const response = companyBotStrategy(data); 10 | 11 | // assert 12 | expect(response).toBe(4.5); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [[4, 1], [4, -1], [0, 0], [6, 1]]; 18 | 19 | // act 20 | const response = companyBotStrategy(data); 21 | 22 | // assert 23 | expect(response).toBe(5.0); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const data = [[4, -1], [0, 0], [5, -1]]; 29 | 30 | // act 31 | const response = companyBotStrategy(data); 32 | 33 | // assert 34 | expect(response).toBe(0); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /companyBotStrategy/companyBotStrategy.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { compareIntegers } from './compareIntegers'; 2 | 3 | xdescribe(compareIntegers.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const a = "12"; 7 | const b = "13" 8 | 9 | // act 10 | const response = compareIntegers(a, b); 11 | 12 | // assert 13 | expect(response).toBe("less"); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const a = "875"; 19 | const b = "799" 20 | 21 | // act 22 | const response = compareIntegers(a, b); 23 | 24 | // assert 25 | expect(response).toBe("greater"); 26 | }); 27 | 28 | it('Test 3', () => { 29 | // arrange 30 | const a = "1000"; 31 | const b = "1000" 32 | 33 | // act 34 | const response = compareIntegers(a, b); 35 | 36 | // assert 37 | expect(response).toBe("equal"); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /compareIntegers/compareIntegers.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { composeRanges } from './composeRanges'; 2 | 3 | xdescribe(composeRanges.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [-1, 0, 1, 2, 6, 7, 9]; 7 | 8 | // act 9 | const response = composeRanges(data); 10 | 11 | // assert 12 | expect(response).toEqual(["-1->2", "6->7", "9"]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /composeRanges/composeRanges.ts: -------------------------------------------------------------------------------- 1 | export function composeRanges(nums: number[]): string[] { 2 | 3 | } 4 | 5 | // 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 | export function confirmEnding(str: string, target: string) { 2 | 3 | } 4 | 5 | // console.log(confirmEnding("Abstraction", "action")); 6 | // console.log(confirmEnding("Open sesame", "pen")); -------------------------------------------------------------------------------- /confirmEnding/confrimEnding.spec.ts: -------------------------------------------------------------------------------- 1 | import { confirmEnding } from './confirmEnding'; 2 | 3 | xdescribe(confirmEnding.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const str1 = "Abstraction"; 7 | const str2 = "action"; 8 | 9 | // act 10 | const response = confirmEnding(str1, str2); 11 | 12 | // assert 13 | expect(response).toBe(true); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const str1 = "Open sesame"; 19 | const str2 = "pen"; 20 | 21 | // act 22 | const response = confirmEnding(str1, str2); 23 | 24 | // assert 25 | expect(response).toBe(false); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /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.spec.ts: -------------------------------------------------------------------------------- 1 | import { containsCloseNums } from './containsCloseNums'; 2 | 3 | xdescribe(containsCloseNums.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const nums = [0, 1, 2, 3, 5, 2]; 7 | const k = 3; 8 | 9 | // act 10 | const response = containsCloseNums(nums, k); 11 | 12 | // assert 13 | expect(response).toBe(true); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const nums = [0, 1, 2, 3, 5, 2]; 19 | const k = 2; 20 | 21 | // act 22 | const response = containsCloseNums(nums, k); 23 | 24 | // assert 25 | expect(response).toBe(false); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /containsCloseNums/containsCloseNums.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { containsDuplicates } from './containsDuplicates'; 2 | 3 | xdescribe(containsDuplicates.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const a = [1, 2, 3, 1]; 7 | 8 | // act 9 | const response = containsDuplicates(a); 10 | 11 | // assert 12 | expect(response).toBe(true); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const a = [3, 1]; 18 | 19 | // act 20 | const response = containsDuplicates(a); 21 | 22 | // assert 23 | expect(response).toBe(false); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /containsDuplicates/containsDuplicates.ts: -------------------------------------------------------------------------------- 1 | export 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 | **Example** 9 | - celsiusToFahrenheit(-30) returns -22; 10 | - celsiusToFahrenheit(-10) returns 14; 11 | - celsiusToFahrenheit(0) returns 32; 12 | -------------------------------------------------------------------------------- /convertCelsiusToFahrenheit/convertCelsiusToFahrenheit.spec.ts: -------------------------------------------------------------------------------- 1 | import { celsiusToFahrenheit } from './convertCelsiusToFahrenheit'; 2 | 3 | xdescribe(celsiusToFahrenheit.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = -30; 7 | 8 | // act 9 | const response = celsiusToFahrenheit(data); 10 | 11 | // assert 12 | expect(response).toBe(-22); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = -10; 18 | 19 | // act 20 | const response = celsiusToFahrenheit(data); 21 | 22 | // assert 23 | expect(response).toBe(14); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const data = 0; 29 | 30 | // act 31 | const response = celsiusToFahrenheit(data); 32 | 33 | // assert 34 | expect(response).toBe(32); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /convertCelsiusToFahrenheit/convertCelsiusToFahrenheit.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { convertString } from './convertString'; 2 | 3 | xdescribe(convertString.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const s = 'ceoydefthf5iyg5h5yts'; 7 | const t = 'codefights'; 8 | 9 | // act 10 | const response = convertString(s, t); 11 | 12 | // assert 13 | expect(response).toBe(true); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const s = 'addbyca'; 19 | const t = 'abcd'; 20 | 21 | // act 22 | const response = convertString(s, t); 23 | 24 | // assert 25 | expect(response).toBe(false); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /convertString/convertString.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { crossingSum } from './crossingSum'; 2 | 3 | xdescribe(crossingSum.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const matrix = [[1, 1, 1, 1], 7 | [2, 2, 2, 2], 8 | [3, 3, 3, 3]]; 9 | const a = 1; 10 | const b = 3; 11 | 12 | // act 13 | const response = crossingSum(matrix, a, b); 14 | 15 | // assert 16 | expect(response).toBe(true); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /crossingSum/crossingSum.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { depositProfit } from './depositProfit'; 2 | 3 | xdescribe(depositProfit.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const deposit = 100; 7 | const rate = 20; 8 | const threshold = 170; 9 | 10 | // act 11 | const response = depositProfit(deposit, rate, threshold); 12 | 13 | // assert 14 | expect(response).toBe(3); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /depositProfit/depositProfit.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { differentSymbolsNaive } from './differentSymbolsNaive'; 2 | 3 | xdescribe(differentSymbolsNaive.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const s = 'cabca'; 7 | 8 | // act 9 | const response = differentSymbolsNaive(s); 10 | 11 | // assert 12 | expect(response).toBe(3); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /differentSymbolsNaive/differentSymbolsNaive.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { digitDegree } from './digitDegree'; 2 | 3 | xdescribe(digitDegree.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const n = 5; 7 | 8 | // act 9 | const response = digitDegree(n); 10 | 11 | // assert 12 | expect(response).toBe(0); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const n = 100; 18 | 19 | // act 20 | const response = digitDegree(n); 21 | 22 | // assert 23 | expect(response).toBe(1); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const n = 91; 29 | 30 | // act 31 | const response = digitDegree(n); 32 | 33 | // assert 34 | expect(response).toBe(1); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /digitDegree/digitDegree.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { domainType } from './domainType'; 2 | 3 | xdescribe(domainType.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const domains = ["en.wiki.org", "codefights.com", "happy.net", "code.info"]; 7 | 8 | // act 9 | const response = domainType(domains); 10 | 11 | // assert 12 | expect(response).toEqual(["organization", "commercial", "network", "information"]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /domainType/domainType.ts: -------------------------------------------------------------------------------- 1 | export function domainType(domains: string[]): string[] { 2 | 3 | } 4 | 5 | // console.log(domainType(["en.wiki.org", "codefights.com", "happy.net", "code.info"])); -------------------------------------------------------------------------------- /electionWinners/electionWinners.spec.ts: -------------------------------------------------------------------------------- 1 | import { electionsWinners } from './electionWinners'; 2 | 3 | xdescribe(electionsWinners.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const votes = [2, 3, 5, 2]; 7 | const k = 3; 8 | 9 | // act 10 | const response = electionsWinners(votes, k); 11 | 12 | // assert 13 | expect(response).toBe(2); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /electionWinners/electionWinners.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { encloseInBrackets } from './encloseInBrackets'; 2 | 3 | xdescribe(encloseInBrackets.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const inputString = 'abacaba'; 7 | 8 | // act 9 | const response = encloseInBrackets(inputString); 10 | 11 | // assert 12 | expect(response).toBe('(abacaba)'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /encloseInBrackets/encloseInBrackets.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { evenDigitsOnly } from './evenDigitsOnly'; 2 | 3 | xdescribe(evenDigitsOnly.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const n = 248622; 7 | 8 | // act 9 | const response = evenDigitsOnly(n); 10 | 11 | // assert 12 | expect(response).toBe(true); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const n = 642386; 18 | 19 | // act 20 | const response = evenDigitsOnly(n); 21 | 22 | // assert 23 | expect(response).toBe(false); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /evenDigitsOnly/evenDigitsOnly.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { extractEachKth } from './extractEachKth'; 2 | 3 | xdescribe(extractEachKth.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 7 | const k = 3; 8 | 9 | // act 10 | const response = extractEachKth(inputArray, k); 11 | 12 | // assert 13 | expect(response).toEqual([1, 2, 4, 5, 7, 8, 10]); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /extractEachKth/extractEachKth.ts: -------------------------------------------------------------------------------- 1 | export 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 | and column = 2, the output should be 13 | extractMatrixColumn(matrix, column) = [1, 0, 3]. 14 | 15 | **Hints** 16 | - push() 17 | 18 | **Input/Output** 19 | 20 | - **[execution time limit] 5 seconds (ts)** 21 | - **[input] array.array.integer matrix** 22 | 2-dimensional array of integers representing a rectangular matrix. 23 | 24 | *Guaranteed constraints:* 25 | 1 ≤ matrix.length ≤ 4, 26 | 1 ≤ matrix[0].length ≤ 4, 27 | 0 ≤ matrix[i][j] ≤ 300. 28 | 29 | - **[input] integer column** 30 | An integer not greater than the number of matrix columns. 31 | 32 | *Guaranteed constraints:* 33 | 0 ≤ column ≤ matrix[i].length - 1. 34 | 35 | - **[output] array.integer** 36 | -------------------------------------------------------------------------------- /extractMatrixColumn/extractMatrixColumn.spec.ts: -------------------------------------------------------------------------------- 1 | import { extractMatrixColumn } from './extractMatrixColumn'; 2 | 3 | xdescribe(extractMatrixColumn.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const matrix = [ 7 | [1, 1, 1, 2], 8 | [0, 5, 0, 4], 9 | [2, 1, 3, 6] 10 | ]; 11 | const column = 2; 12 | 13 | // act 14 | const response = extractMatrixColumn(matrix, column); 15 | 16 | // assert 17 | expect(response).toEqual([1, 0, 3]); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /extractMatrixColumn/extractMatrixColumn.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { factorializeANumber } from './factorializeANumber'; 2 | 3 | xdescribe(factorializeANumber.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 5; 7 | 8 | // act 9 | const response = factorializeANumber(data); 10 | 11 | // assert 12 | expect(response).toBe(120); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 10; 18 | 19 | // act 20 | const response = factorializeANumber(data); 21 | 22 | // assert 23 | expect(response).toBe(3628800); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /factorializeANumber/factorializeANumber.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { fancyRide } from './fancyRide'; 2 | 3 | xdescribe(fancyRide.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const l = 30; 7 | const fares = [0.3, 0.5, 0.7, 1, 1.3]; 8 | 9 | // act 10 | const response = fancyRide(l, fares); 11 | 12 | // assert 13 | expect(response).toBe('UberXL'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /fancyRide/fancyRide.ts: -------------------------------------------------------------------------------- 1 | export 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/fareEstimator.spec.ts: -------------------------------------------------------------------------------- 1 | import { fareEstimator } from './fareEstimator'; 2 | 3 | xdescribe(fareEstimator.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const ride_time = 30; 7 | const ride_distance = 7; 8 | const cost_per_minute = [0.2, 0.35, 0.4, 0.45]; 9 | const cost_per_mile = [1.1, 1.8, 2.3, 3.5]; 10 | 11 | // act 12 | const response = fareEstimator(ride_time, ride_distance, cost_per_minute, cost_per_mile); 13 | 14 | // assert 15 | expect(response).toEqual([13.7, 23.1, 28.1, 38]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /fareEstimator/fareEstimator.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { fermactor } from './fermactor'; 2 | 3 | xdescribe(fermactor.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const n = 15; 7 | 8 | // act 9 | const response = fermactor(n); 10 | 11 | // assert 12 | expect(response).toEqual([4, 1]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /fermactor/fermactor.ts: -------------------------------------------------------------------------------- 1 | export 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/findCloserPair.spec.ts: -------------------------------------------------------------------------------- 1 | import { findClosestPair } from './findClosestPair'; 2 | 3 | xdescribe(findClosestPair.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const numbers = [1, 0, 2, 4, 3, 0]; 7 | const sum = 5; 8 | 9 | // act 10 | const response = findClosestPair(numbers, sum); 11 | 12 | // assert 13 | expect(response).toEqual(2); 14 | }); 15 | 16 | it('Test 2', () => { 17 | // arrange 18 | const numbers = [2, 3, 7]; 19 | const sum = 8; 20 | 21 | // act 22 | const response = findClosestPair(numbers, sum); 23 | 24 | // assert 25 | expect(response).toEqual(-1); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /findClosestPair/findClosestPair.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { findEmailDomain } from './findEmailDomain'; 2 | 3 | xdescribe(findEmailDomain.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const address = 'prettyandsimple@example.com'; 7 | 8 | // act 9 | const response = findEmailDomain(address); 10 | 11 | // assert 12 | expect(response).toBe('example.com'); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const address = '<>[]:,;@\"!#$%&*+-/=?^_{}| ~.a\"@example.org'; 18 | 19 | // act 20 | const response = findEmailDomain(address); 21 | 22 | // assert 23 | expect(response).toBe('example.org'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /findEmailDomain/findEmailDomain.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { firstDigit } from './firstDigit'; 2 | 3 | xdescribe(firstDigit.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const inputString = 'var_1__Int'; 7 | 8 | // act 9 | const response = firstDigit(inputString); 10 | 11 | // assert 12 | expect(response).toBe('1'); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const inputString = 'q2q-q'; 18 | 19 | // act 20 | const response = firstDigit(inputString); 21 | 22 | // assert 23 | expect(response).toBe('2'); 24 | }); 25 | 26 | it('Test 3', () => { 27 | // arrange 28 | const inputString = '0ss'; 29 | 30 | // act 31 | const response = firstDigit(inputString); 32 | 33 | // assert 34 | expect(response).toBe('0'); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /firstDigit/firstDigit.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { firstDuplicate } from './firstDuplicate'; 2 | 3 | xdescribe(firstDuplicate.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [2, 1, 3, 5, 3, 2]; 7 | 8 | // act 9 | const response = firstDuplicate(data); 10 | 11 | // assert 12 | expect(response).toBe(3); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [2, 4, 3, 5, 1]; 18 | 19 | // act 20 | const response = firstDuplicate(data); 21 | 22 | // assert 23 | expect(response).toBe(-1); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /firstDuplicate/firstDuplicate.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { firstNotRepeatingCharacter } from './firstNotRepeatingCharacter'; 2 | 3 | xdescribe(firstNotRepeatingCharacter.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = 'abacabad'; 7 | 8 | // act 9 | const response = firstNotRepeatingCharacter(data); 10 | 11 | // assert 12 | expect(response).toBe('c'); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = 'abacabaabacaba'; 18 | 19 | // act 20 | const response = firstNotRepeatingCharacter(data); 21 | 22 | // assert 23 | expect(response).toBe('_'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /firstNotRepeatingCharacter/firstNotRepeatingCharacter.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { flattenArray } from './flattenArray'; 2 | 3 | xdescribe(flattenArray.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [[["a"]], [["b"]]]; 7 | 8 | // act 9 | const response = flattenArray(data); 10 | 11 | // assert 12 | expect(response).toEqual(["a", "b"]); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const data = [1, [2], [3, [[4]]]]; 18 | 19 | // act 20 | const response = flattenArray(data); 21 | 22 | // assert 23 | expect(response).toEqual([1, 2, 3, 4]); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /flattenArray/flattenArray.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { growingPlant } from './growingPlant'; 2 | 3 | xdescribe(growingPlant.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const upSpeed = 100; 7 | const downSpeed = 10; 8 | const desiredHeight = 910; 9 | 10 | // act 11 | const response = growingPlant(upSpeed, downSpeed, desiredHeight); 12 | 13 | // assert 14 | expect(response).toBe(10); 15 | }); 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /growingPlant/growingPlant.ts: -------------------------------------------------------------------------------- 1 | export 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/houseNumberSum.spec.ts: -------------------------------------------------------------------------------- 1 | import { houseNumbersSum } from './houseNumbersSum'; 2 | 3 | xdescribe(houseNumbersSum.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const data = [5, 1, 2, 3, 0, 1, 5, 0, 2]; 7 | 8 | // act 9 | const response = houseNumbersSum(data); 10 | 11 | // assert 12 | expect(response).toBe(10); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /houseNumbersSum/houseNumbersSum.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { houseOfCats } from './houseOfCats'; 2 | 3 | xdescribe(houseOfCats.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const legs = 6; 7 | 8 | // act 9 | const response = houseOfCats(legs); 10 | 11 | // assert 12 | expect(response).toEqual([1, 3]); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const legs = 2; 18 | 19 | // act 20 | const response = houseOfCats(legs); 21 | 22 | // assert 23 | expect(response).toEqual([1]); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /houseOfCats/houseOfCats.ts: -------------------------------------------------------------------------------- 1 | export 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.spec.ts: -------------------------------------------------------------------------------- 1 | import { htmlEndTagByStartTag } from './htmlEndTagByStartTag'; 2 | 3 | xdescribe(htmlEndTagByStartTag.name, () => { 4 | it('Test 1', () => { 5 | // arrange 6 | const startTag = ""); 13 | }); 14 | 15 | it('Test 2', () => { 16 | // arrange 17 | const startTag = ''; 18 | 19 | // act 20 | const response = htmlEndTagByStartTag(startTag); 21 | 22 | // assert 23 | expect(response).toEqual(''); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /htmlEndTagByStartTag/htmlEndTagByStartTag.ts: -------------------------------------------------------------------------------- 1 | export function htmlEndTagByStartTag(startTag: string): string { 2 | 3 | } 4 | 5 | // console.log(htmlEndTagByStartTag("