Question Given a sorted array of integers a, your task is to determine which element of a is closest to all other values of a. In other words, find the element x in a, which minimizes the following sum: abs(a[0] - x) + abs(a[1] - x) + ... + abs(a[a.length - 1] - x) (where abs denotes the absolute value) If there are several possible answers, output the smallest one. Example For a = [2, 4, 7], th..
Question You have deposited a specific amount of money into your bank account. Each year your balance increases at the same growth rate. With the assumption that you don't make any additional deposits, find out how long it would take for your balance to pass a specific threshold. Example For deposit = 100, rate = 20, and threshold = 170, the output should be depositProfit(deposit, rate, thre..
Question 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. Input/Output [execution time limit] 4 seconds (py3) [input] string cell1 Guaranteed cons..
Question Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a). Example For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz". Input/Output [execution time limit] 4 seconds (py3) [input] string inputString A non-empty string consisting of lowe..
Question Correct variable names consist only of English 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; For name = "2w2", the output should be variableName(name) = false. I..
Question 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 [execution time limit] 4 seconds (py3) [input] integer n Guaranteed constraints: 1 ≤ n ≤ 109. [output] boolean true if all digits of n are even, false otherwise. MY_ANSWER def evenDigitsOnly..
Question 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 [execution time limit] 4 seconds (py3) [input] array.integer inputArray Guaranteed constraints: 0 ≤ inputAr..
Question In the popular Minesweeper game you have a board with some mines and those cells that don't contain a mine have a number in it that indicates the total number of mines in the neighboring cells. Starting off with some arrangement of mines we want to create a Minesweeper game setup. Example For matrix = [[true, false, false], [false, true, false], [false, false, false]] the output sho..