Question 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. Example For inputArray = [1, 1, 1], the output should be arrayChange(inputArray) = 3. For inputArray = [2, 1, 10, 1], the output should be arrayChange(inputArray) = 12. Input/Out..
Question 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. Given two arrays a and b, check whether they are similar. Example For a = [1, 2, 3] and b = [1, 2, 3], the output should be areSimilar(a, b) = true. The arrays are equal, no need to swap any elements. For a = [1, 2, 3] and b = [2, 1, 3], the output should be a..
Question Given a rectangular matrix of characters, add a border of asterisks(*) to it. Example For picture = ["abc", "ded"] the output should be addBorder(picture) = ["*****", "*abc*", "*ded*", "*****"] Input/Output [execution time limit] 4 seconds (py3) [input] array.string picture A non-empty array of non-empty equal-length strings. Guaranteed constraints: 1 ≤ picture.length ≤ 100, 1 ≤ picture..
Question 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. 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 elem..
Question Write a function that reverses characters in (possibly nested) parentheses in the input string. Input strings will always be well-formed with matching ()s. Example For inputString = "(bar)", the output should be reverseInParentheses(inputString) = "rab"; For inputString = "foo(bar)baz", the output should be reverseInParentheses(inputString) = "foorabbaz"; For inputString = "foo(bar)baz(..
문제 왼쪽 위 코너의 좌표 (0, 0), 오른쪽 아래 코너의 좌표 (w-1, h-1) 총 두 개의 좌표로 사각형을 표현한다고 하자. rect1 = [x1, y1, x2, y2], rect2 = [x3, y3, x4, y4] 두 개의 사각형의 겹치는 넓이는 구하여라. 먼저 사각형이 겹치는 케이스를 여러가지로 고려해보자. 회색 사각형을 기준으로 한쪽 귀퉁이를 덮음 한 변을 덮음 자신의 한 변이 모두 덮임 교차 자신이 포함됨 다른 사각형을 모두 덮음 겹치지 않음 겹치는 사례를 나누어서 처리할 수 있으나 겹치는 영역은 공통점이 있기 때문에 하나의 사례로 처리한다. 겹치는 영역의 왼쪽 변은, 기존 두 사각형의 왼쪽 변 중에서 더 오른쪽에 있는 것 위쪽 변은, 기존 두 사각형의 위쪽 변 중에서 더 아래쪽에 있는 것..
Question Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees. People can be very tall! Example For a = [-1, 150, 190, 170, -1, -1, 160, 180], the output should be sortByHeight(a) = [-1, 150, 160, 170, -1, -1, 180, 190]. Input/Output [execution time..
Question Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if the sum of the first half of the digits is equal to the sum of the second half. Given a ticket number n, determine if it's lucky or not. Example For n = 1230, the output should be isLucky(n) = true; For n = 239017, the output should be isLucky(n) = false. Input/Output [execution time l..