Welcome to my personal website. I use this space to share some of my thoughts and software that I write in my free time. Sometimes I also publish photos. If you want to get in touch please use LinkedIn or Mastodon.
Given a matrix of characters, return True if the word is contained within the matrix by visiting horizontally and vertically adjacent fields.
The solution involves backtracking which means that we have to mark the character on the board as visited. In this case it is relatively simple as valid characters contain only [A-Z] so that we can take a - to mark a visited field and know that this will not appear in the word that we’re looking for.
Furthermore it helps to see the problem as a tree instead of a matrix. Once we find the first initial position (which there could be multiple of), select it as a root node and move from there left, right, up and down in any order. Once we found the first viable solution, we return True.
About the author
Friedrich Ewald is an experienced Software Engineer with a Master's degree in Computer Science. He started this website in late 2015, mostly as a digital business card. He is interested in Go, Python, Ruby, SQL- and NoSQL-databases, machine learning and AI and is experienced in building scalable, distributed systems and micro-services at multiple larger and smaller companies.