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 9250927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:34:09+00:00 2026-06-18T10:34:09+00:00

I just came through this question , and I could not think any better

  • 0

I just came through this question , and I could not think any better approach for other than bruteforce Given a 2D array of chars and a raw list of valid words.
1) Find all the valid words from the array. From each element in the array, you can traverse up, down, right or left.
Eg,

g o d b o d y
t a m o p r n 
u i r u s m p

valid words from the above 2D array -> god, goat, godbody, amour,….

  • 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-18T10:34:10+00:00Added an answer on June 18, 2026 at 10:34 am

    Make sure you have an alphabetically sorted list of valid words. You could build this in n lg n time.

    Now you have this sorted list, you could verify if a sequence of characters is a start of a correct word in lg n time.

    Use a set of valid words to validate if a sequence of letters is a valid word (in constant time).

    Now call getWords(input, startX, startY, new ArrayList(), “”) for every startposition and merge the resulting lists:

    public List<String> getWords(char[][] input, int x, int y, List<String> result, String current){
        if(isValidWord(current))
             result.add(current);
    
        if(isValidStartOfWord(current)){
             // call getWords recursively for all valid directions, concatenating the char to current
        }
    
        return result;
     }
    

    This way you will find your answer in O(x^2 * y^2 * lg w) time, with x and y dimensions of char array and w the size of the valid word list. That is not better than worst case (given the lg w validation), but that does not seem possible to me. The expected runtime is better this way.

    If the list of valid words is small, you could also build a set for all valid starts of a correct word. In that case, you could verify in constant time if you are on your way to a correct word, and worst case is reduced to O(x^2 * y^2).

    Good luck.

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

Sidebar

Related Questions

An interesting thread came up when I typed in this question just now. I
I was just reading through Learning Python by Mark Lutz and came across this
Just came across this by Chris Coyier - http://css-tricks.com/examples/CSSTabs/ Can anyone explain me, how
I was just going through some codes of C++. Where in I came across
I am working my way through some samples, and came up with this working
This is a question that came from an earlier problem I had . Basically,
This question came up in the comments of this answer . The inability to
I am studying for an exam and came across this question that seems a
I was going through a blog and one question came to my head. Is
I was looking around for jQuery grid recommendations and came across this question/answers: https://stackoverflow.com/questions/159025/jquery-grid-recommendations

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.