Given a rectangular matrix of characters, add a border of asterisks(*) to it.
For
picture = ["abc",
"ded"]
the output should be
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.
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.
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.
For inputArray = [1, 1, 1]
, the output should be
arrayChange(inputArray) = 3
.
Call two arms equally strong if the heaviest weights they each are able to lift are equal.
Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms.
Given your and your friend's arms' lifting capabilities find out if you two are equally strong.
For yourLeft = 10
, yourRight = 15
, friendsLeft = 15
and friendsRight = 10
, the output should be
areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true
;
An IP address is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. There are two versions of the Internet protocol, and thus two versions of addresses. One of them is the IPv4 address.
IPv4 addresses are represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1.
Given a string, find out if it satisfies the IPv4 address naming rules.
For inputString = "172.16.254.1"
, the output should be
isIPv4Address(inputString) = true
;
You are given an array of integers representing coordinates of obstacles situated on a straight line.
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.
Find the minimal length of the jump enough to avoid all the obstacles.
For inputArray = [5, 3, 6, 7, 9]
, the output should be
avoidObstacles(inputArray) = 4
.
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.
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.
As pixel's value is an integer, all fractions should be rounded down.
For
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.
For
matrix = [[true, false, false],
[false, true, false],
[false, false, false]]