Skip to content

Instantly share code, notes, and snippets.

View Nicknyr's full-sized avatar

Nick Kinlen Nicknyr

  • South Florida
View GitHub Profile
@Nicknyr
Nicknyr / magicWell.js
Created February 9, 2021 00:44
CodeSignal: Magic Well
/*
You are standing at a magical well. It has two positive integers written on it: a and b. Each time you cast a magic marble into the well, it gives you a * b dollars and then both a and b increase by 1. You have n magic marbles. How much money will you make?
Example
For a = 1, b = 2, and n = 2, the output should be
magicalWell(a, b, n) = 8.
You will cast your first marble and get $2, after which the numbers will become 2 and 3. When you cast your second marble, the well will give you $6. Overall, you'll make $8. So, the output is 8.
@Nicknyr
Nicknyr / validTime.js
Created February 9, 2021 00:35
CodeSignal: Valid Time
/*
Check if the given string is a correct time representation of the 24-hour clock.
Example
For time = "13:58", the output should be
validTime(time) = true;
For time = "25:51", the output should be
validTime(time) = false;
@Nicknyr
Nicknyr / extractMatrixColumn.js
Created August 28, 2020 12:39
Code Signal - Extract Matrix Column
/*
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).
Example
For
matrix = [[1, 1, 1, 2],
[0, 5, 0, 4],
[2, 1, 3, 6]]
@Nicknyr
Nicknyr / sumOfTwo.js
Created July 12, 2020 23:24
CodeSignal - sumOfTwo
/*
You have two integer arrays, a and b, and an integer target value v. Determine whether there is a pair of numbers, where one number is taken from a and the other from b, that can be added together to get a sum of v. Return true if such a pair exists, otherwise return false.
Example
For a = [1, 2, 3], b = [10, 20, 30, 40], and v = 42, the output should be
sumOfTwo(a, b, v) = true.
*/
function sumOfTwo(a, b, v) {
@Nicknyr
Nicknyr / characterParity.js
Created April 17, 2020 20:29
CodeSignal - Character Parity
/*
Given a character, check if it represents an odd digit, an even digit or not a digit at all.
Example
For symbol = '5', the output should be
characterParity(symbol) = "odd";
For symbol = '8', the output should be
characterParity(symbol) = "even";
For symbol = 'q', the output should be
@Nicknyr
Nicknyr / alphabetSubsequence.js
Created April 17, 2020 19:48
CodeSignal - Alphabet Subsequence
/*
Check whether the given string is a subsequence of the plaintext alphabet.
Example
For s = "effg", the output should be
alphabetSubsequence(s) = false;
For s = "cdce", the output should be
alphabetSubsequence(s) = false;
For s = "ace", the output should be
@Nicknyr
Nicknyr / allLongestStrings.js
Created April 17, 2020 18:13
CodeSignal - All Longest Strings
/*
Given an array of strings, return another array containing all of its longest strings.
Example
For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be
allLongestStrings(inputArray) = ["aba", "vcd", "aba"].
*/
function allLongestStrings(inputArray) {
@Nicknyr
Nicknyr / houseNumbersSum.js
Created April 17, 2020 17:49
CodeSignal - House Numbers Sum
/*
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.
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.
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.
Example
For inputArray = [5, 1, 2, 3, 0, 1, 5, 0, 2], the output should be
@Nicknyr
Nicknyr / findEmailDomain.js
Created April 14, 2020 01:40
CodeSignal - Find Email Domain
/*
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").
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.
Given a valid email address, find its domain part.
Example
For address = "prettyandsimple@example.com", the output should be
@Nicknyr
Nicknyr / properNounCorrection.js
Created April 13, 2020 22:44
CodeSignal - Proper Noun Correction
/*
Proper nouns always begin with a capital letter, followed by small letters.
Correct a given proper noun so that it fits this statement.
Example
For noun = "pARiS", the output should be
properNounCorrection(noun) = "Paris";
For noun = "John", the output should be