AlgoDaily Solution
1Locked, only available for premium members.
Community Solutions
Community solutions are only available for premium users.
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.
xxxxxxxxxx
69
var assert = require('assert');
function smallestDist(matrix, A, B) {
// Fill in
}
try {
let matrix = [
['x', 'x', 'A', 'x', 'B'],
['x', 'A', 'x', 'x', 'x'],
['x', 'x', 'x', 'B', 'x'],
['A', 'x', 'x', 'x', 'x'],
['x', 'A', 'x', 'A', 'A'],
];
let result = smallestDist(matrix, 'A', 'B');
assert.equal(2, result, 'Wrong Answer');
console.log(
'PASSED: ' +
"The below matrix with A='A' and B='B' should return 2.let matrix = [ ['x', 'x', 'A', 'x', 'B'], ['x', 'A', 'x', 'x', 'x'], ['x', 'x', 'x', 'B', 'x'], ['A', 'x', 'x', 'x', 'x'], ['x', 'A', 'x', 'A', 'A'],]"
);
} catch (err) {
console.log(err);
}
try {
let matrix = [
OUTPUT
Results will appear here.