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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:40:51+00:00 2026-06-12T20:40:51+00:00

I was asked this question at an interview and I’m curious about the optimal

  • 0

I was asked this question at an interview and I’m curious about the optimal answer. The question is like this: you are given an n x n board filled with letters. a gaming algorithm wants to find and list all the possible words on this board, where “a word” is defined as a string of at least 3 letters, either horizontally or vertically. what’s the most time efficient way to do this?

the “word” in this question DOES NOT need to be a real word from a dictionary. the point is to find all strings of acceptable length as FAST as possible. I couldn’t think of anything else except for the brutal force approach that traverses through all spaces on the board and find all strings starting with the letter in that space, which requires O(n^3) time. how would you guys do it?

PS. I see this question got downvoted because people don’t think there’s a better solution. This, however, is a microsoft interview question and my interviewer explicitly told me that my answer was not optimal.

  • 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-12T20:40:52+00:00Added an answer on June 12, 2026 at 8:40 pm

    Let m(x) = max {0, x}. If we use 0-based indices, there are

    s(x,y) = m(x-1) + m(n-x-2) + m(y-1) + m(n-y-2)
    

    words starting at position (x,y). Horizontally, to the left those ending in column 0, 1, ..., y-2 and to the right those ending in column x+2, x+3, ..., n-1. Similar for the vertical words.

    So at each position there start between 2*(n-3) and 2*(n-2) words (inclusive).

    More precisely, at position (x,y), there start n-2 horizontal words if and only if y = 0 or y = n-1, n-3 words otherwise. That makes 2*(n-2) + (n-2)*(n-3) = (n-1)*(n-2) horizontal words per row. The number of vertical words per column is the same, so altogether there are

    2*n*(n-1)*(n-2)
    

    not necessarily distinct words in the grid. Assuming a not too small alphabet, the proportion of duplicates is on average not large, so it’s impossible to have an algorithm of complexity below O(n³).

    If duplicates shall not be considered, that’s it, and there remains only the low-level variations of traversing the array.

    If duplicates shall be removed, and the target is to list all distinct words as efficiently as possible, the question is what data structure allows to remove the duplicates as efficiently as possible. I can’t answer that, but I think a trie would be rather efficient for that.

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

Sidebar

Related Questions

Recently I was asked this question in an interview. I gave an answer in
I was asked this question in a job interview, and I'd like to know
Hi i was asked in an interview about this question. I did google a
I was asked this interview question. I am not sure what the correct answer
I was asked this question during phone interview. Given two strings find the minimal
I was asked this question in an interview Plz tell me the answer :-
I have recently given an interview. I was asked this question in interview. I
I recently was asked this question in an interview and would like to hear
Interview Question I have been asked this question in an interview, and the answer
I was asked this question in an interview and I said the answer was

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.