1) Sorting array of words that differ by one char
Given an array of equal-length strings, you'd like to know if it's possible to rearrange the order of the elements in such a way that each consecutive pair of strings differ by exactly one character. Return true
if it's possible, and false
if not.
Note: You're only rearranging the order of the strings, not the order of the letters within the strings!
Example
- For
inputArray = ["aba", "bbb", "bab"]
, the output should besolution(inputArray) = false
. ["aba", "bbb", "bab"]
["aba", "bab", "bbb"]
["bbb", "aba", "bab"]
["bbb", "bab", "aba"]
["bab", "bbb", "aba"]
["bab", "aba", "bbb"]
- For
inputArray = ["ab", "bb", "aa"]
, the output should besolution(inputArray) = true
.
There are 6 possible arrangements for these strings:
None of these satisfy the condition of consecutive strings differing by 1 character, so the answer is false
.
It's possible to arrange these strings in a way that each consecutive pair of strings differ by 1 character (eg: "aa", "ab", "bb"
or "bb", "ab", "aa"
), so return true
.
2) Find digit degree
Let's define digit degree of some positive integer as the number of times we need to replace this number with the sum of its digits until we get to a one digit number.
Given an integer, find its digit degree.
Example
- For
n = 5
, the output should besolution(n) = 0
; - For
n = 100
, the output should besolution(n) = 1
.1 + 0 + 0 = 1
. - For
n = 91
, the output should besolution(n) = 2
.9 + 1 = 10
->1 + 0 = 1
.
3) Build a palindrome string
Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome.
Example
For st = "abcdc"
, the output should besolution(st) = "abcdcba"
.
4) Sudoku
Sudoku is a number-placement puzzle. The objective is to fill a 9 × 9
grid with digits so that each column, each row, and each of the nine 3 × 3
sub-grids that compose the grid contains all of the digits from 1
to 9
.
This algorithm should check if the given grid of numbers represents a correct solution to Sudoku.
Example
- For
grid = [[1, 3, 2, 5, 4, 6, 9, 8, 7],
[4, 6, 5, 8, 7, 9, 3, 2, 1],
[7, 9, 8, 2, 1, 3, 6, 5, 4],
[9, 2, 1, 4, 3, 5, 8, 7, 6],
[3, 5, 4, 7, 6, 8, 2, 1, 9],
[6, 8, 7, 1, 9, 2, 5, 4, 3],
[5, 7, 6, 9, 8, 1, 4, 3, 2],
[2, 4, 3, 6, 5, 7, 1, 9, 8],
[8, 1, 9, 3, 2, 4, 7, 6, 5]]
the output should besolution(grid) = true
;
- For
grid = [[8, 3, 6, 5, 3, 6, 7, 2, 9],
[4, 2, 5, 8, 7, 9, 3, 8, 1],
[7, 9, 1, 2, 1, 4, 6, 5, 4],
[9, 2, 1, 4, 3, 5, 8, 7, 6],
[3, 5, 4, 7, 6, 8, 2, 1, 9],
[6, 8, 7, 1, 9, 2, 5, 4, 3],
[5, 7, 6, 9, 8, 1, 4, 3, 2],
[2, 4, 3, 6, 5, 7, 1, 9, 8],
[8, 1, 9, 3, 2, 4, 7, 6, 5]]
the output should besolution(grid) = false
.
The output should be false
: each of the nine 3 × 3
sub-grids should contain all of the digits from 1
to 9
.These examples are represented on the image below.

5) Diagonal with rectangulars
Imagine a white rectangular grid of n
rows and m
columns divided into two parts by a diagonal line running from the upper left to the lower right corner. Now let's paint the grid in two colors according to the following rules:
- A cell is painted black if it has at least one point in common with the diagonal;
- Otherwise, a cell is painted white.
Count the number of cells painted black.
Example
- For
n = 3
andm = 4
, the output should besolution(n, m) = 6
. - For
n = 3
andm = 3
, the output should besolution(n, m) = 7
.
There are 6
cells that have at least one common point with the diagonal and therefore are painted black.

7
cells have at least one common point with the diagonal and are painted black.

Добавляйтесь в друзья https://app.codesignal.com/profile/vlad360