Hacker News new | past | comments | ask | show | jobs | submit login

And that reminded me that some people were nervous about doing the nested loop solution so asked if they could "brute force" it and we would accept that. Interview stress is a thing after all.

I'm intrigued by the slice/map solution. It would have been perfectly acceptable if you could explain what the functions did. In fact, it would have led to very probing conversations: my usual interview partner and me had a deep interest in elegant solutions.




   grid.slice(x,x+3)
Turns the 10x10 array into a 3x10 discarding the rows before and after the target rows.

If the second value in slice is larger than the length it slices to the end. It could be a 2x10 or 1x10 but lets pretend it is 3.

   .map(g=>g.slice(y,y+3))
Does the same with each row making it into a 3x3 (or 2x3 or 1x1 etc)

   .flat()
Turns the 3x3 into a flat array of up to 9 values.

   .includes(num)
tests if the flat sliced array include num.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: