Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:53:06+00:00 2026-06-15T11:53:06+00:00

Stumbled upon this interview question recently, Given a 2-dimensional array of characters and a

  • 0

Stumbled upon this interview question recently,

Given a 2-dimensional array of characters and a dictionary in which a word can be searched in O(1) time. Need to print all the words from array which are present in dictionary. Word can be formed in any direction but has to end at any edge of array.(Need not worry much about the dictionary)

Input:

a f h u n
e t a i r
a e g g o
t r m l p

Output:

after
hate
hair
air
eat
tea

Note: Here “egg” is not a dictionary word because its not ending at the edge of array.

I’ve seen similar questions before, but was never able to think of a good algorithm to solve these kind of problems. Any help on how to approach these kind of problems (forming words from arrays of characters) will be highly helpful.

(The only way I could think of is to find all possible permutations of characters in the 2D array, and check if it ends on the edge of the array, and check if the permutation is a valid word from the dictionary in O(1) time)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:53:07+00:00Added an answer on June 15, 2026 at 11:53 am

    Turn the array into a graph so that each cell [i,j]
    has an edge shared with each one of its 4 neighbors [i+1,j], [i-1,j], [i,j+1], [i,j-1].
    Then run DFS at each array-edge-cell and and keep checking the dictionary whether
    the word in reverse is in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on topcoder recently and I stumbled upon this question which I
I stumbled upon this question: 7 power 7 is 823543. Which higher power of
I was going through some interview question and stumbled upon this question. p(x) =
Today I stumbled upon this thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/112560 The question is basically how to make
I'm pretty new in iphone programming and have stumbled upon this issue which I
I just read this question and stumbled upon the following quote: Scala treats ==
I stumbled upon this add-on which Ajaxifies parts of its target website. https://addons.mozilla.org/en-US/firefox/addon/51789 I
I stumbled upon this question from two years ago. Is there a way to
I recently stumbled upon this page . And I was particularly interested about the
I stumbled upon this question and i realized i forgot a lot of stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.