Skip to content

Commit 480011e

Browse files
author
hasibulislam999
committed
Moving Stones Until Consecutive problem solved
1 parent 780d24c commit 480011e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Title: Moving Stones Until Consecutive
3+
* Description: There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.
4+
* Author: Hasibul Islam
5+
* Date: 15/04/2023
6+
*/
7+
8+
/**
9+
* @param {number} a
10+
* @param {number} b
11+
* @param {number} c
12+
* @return {number[]}
13+
*/
14+
const numMovesStones = (a, b, c) => {
15+
const [x, y, z] = [Math.abs(a - b), Math.abs(b - c), Math.abs(c - a)];
16+
const [min, max] = [Math.min(x, y, z), Math.max(x, y, z)];
17+
return 2 === max ? [0, 0] : [min < 3 ? 1 : 2, max - 2];
18+
};

0 commit comments

Comments
 (0)