SnIPPETsX › @james nugent › Technical Interview Dimitre
Technical Interview Dimitre
JavaScript · by @james nugent · updated Oct 19, 2026 · 71 lines
main.js
// 1-omino
//
// []
//
// 2-omino
//
// [] []
//
// 3-omino
//
// [] [] []
//
// []
// [] []
//
// 4-omino (non exhaustive)
//
// [] []
// [] []
//
// [] [] []
// []
//
// 5-omino (non exhaustive)
//
// [] []
// [] [] []
//
// []
// [] [] []
// []
//
// [ ] [ ] [ ] [ ] [ ]
// [ ] [ ] [ ] [ ] [ ]
// [x] [x] [ ] [ ] [ ]
// [ ] [ ] [ ] [ ] [ ]
// [ ] [ ] [ ] [ ] [ ]
// model n-nomino
// write a method that takes int n and returns random n-nomino
class NNomino {
static generateNNomino(n) {
const matrix = Array.from({ length: n }).fill(' ')
for(let i = 0; i < matrix.length; i++) {
matrix[i] = Array.from({ length: n }).fill(' ')
}
const start = Math.floor(Math.random() * n)
matrix[0][start] = 'x'
let row = 0
let col = start
let length = 1
while(length < n) {
const dirArr = [[-1, 0], [1, 0], [0, -1], [0, 1]]
// pick = pick random array from dirArr
row = row + pick[0];
col = col + pick[1];
// while newRow > n, --newRow, ++newRow if < 0
matrix[row][col] = 'x'
length++
}
return matrix
}
}
Run this JavaScript snippet
Open this snippet on SnIPPETsX to run the JavaScript code in your browser, edit it together with others in real time, or fork it into your own copy. No install or account is needed.