Skip to content

Instantly share code, notes, and snippets.

View tyler-austin's full-sized avatar

Tyler Austin tyler-austin

  • Scale AI
  • Washington DC
  • 19:19 (UTC -04:00)
View GitHub Profile
@tyler-austin
tyler-austin / README.md
Created June 21, 2017 18:45
Code Fights - extractEachKth

Given array of integers, remove each kth element from it.

Example

For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be
extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].

Input/Output

  • [time limit] 4000ms (py3)
@tyler-austin
tyler-austin / README.md
Created June 21, 2017 18:07
Code Fights - stringsRearrangement

Given an array of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.

Example

  • For inputArray = ["aba", "bbb", "bab"], the output should be
    stringsRearrangement(inputArray) = false;

    All rearrangements don't satisfy the description condition.

  • For inputArray = ["ab", "bb", "aa"], the output should be

@tyler-austin
tyler-austin / README.md
Created June 19, 2017 17:46
Code Fights - absoluteValuesSumMinimization

Given a sorted array of integers a, find such an integer x that the value of

abs(a[0] - x) + abs(a[1] - x) + ... + abs(a[a.length - 1] - x)

is the smallest possible (here abs denotes the absolute value). If there are several possible answers, output the smallest one.

Example

For a = [2, 4, 7], the output should be

@tyler-austin
tyler-austin / README.md
Created June 19, 2017 16:52
Code Fights - depositProfit

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.

Example

For deposit = 100, rate = 20 and threshold = 170, the output should be
depositProfit(deposit, rate, threshold) = 3.

Each year the amount of money on your account increases by 20%. It means that throughout the years your balance would be:

  • year 0: 100;
@tyler-austin
tyler-austin / README.md
Last active June 19, 2017 16:14
Code Fights - circleOfNumbers

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).

Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.

Example

For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.

Input/Output

Given two cells on the standard chess board, determine whether they have the same color or not.

Example

For cell1 = "A1" and cell2 = "C3", the output should be
chessBoardCellColor(cell1, cell2) = true.

For cell1 = "A1" and cell2 = "H3", the output should be
chessBoardCellColor(cell1, cell2) = false.

Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a).

Example

For inputString = "crazy", the output should be
alphabeticShift(inputString) = "dsbaz".

Input/Output

  • [time limit] 4000ms (py3)

Correct variable names consist only of Latin letters, digits and underscores and they can't start with a digit.

Check if the given string is a correct variable name.

Example

For name = "var_1__Int", the output should be
variableName(name) = true; For name = "qq-q", the output should be
variableName(name) = false;

@tyler-austin
tyler-austin / README.md
Created June 3, 2017 17:41
Code Fights - evenDigitsOnly

Check if all digits of the given integer are even.

Example

For n = 248622, the output should be
evenDigitsOnly(n) = true;
For n = 642386, the output should be
evenDigitsOnly(n) = false.

Input/Output

@tyler-austin
tyler-austin / README.md
Created June 2, 2017 21:12
Code Fights - arrayReplace

Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem.

Example

For inputArray = [1, 2, 1], elemToReplace = 1 and substitutionElem = 3, the output should be
arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3].

Input/Output

  • [time limit] 4000ms (py3)