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

  • Home
  • SEARCH
  • 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 8694477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:47:56+00:00 2026-06-13T00:47:56+00:00

Write a method in Java that returns true if there are k adjacent occurrences

  • 0

“Write a method in Java that returns true if there are k adjacent occurrences of a symbol in the same row, column, or diagonal of a checkered board (two-dimensional array), where k is the number of symbols inline desired.”

How can I do this? I have a rough idea of how to check rows and columns (very rough; no code, just thoughts) but I’m at a loss for checking the diagonal.

Edit: one other situation I’m thinking about: how can I check arbitrary positions? Right now, I’m only considering occurrences starting at (0,0), but what if there’s a string of 3 from, say, (2,3) to (2,6)? How could I keep track of multiple occurrences?

EDIT: Detecting the left diagonal (rough code for a question I posted in the comments below):

LeftDiagonal(x, symbol) {
    noOfOccurence = 0;

    for (currentX = (size - 1); currentX >= x; currentX--) {
        if (board[currentX][currentX] == symbol) {
            noOfOccurence++;
        } else {
            break;
        }
    }

    return (noOfOccurence >= k);
}
  • 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-13T00:47:57+00:00Added an answer on June 13, 2026 at 12:47 am

    The simplest (though not the most efficient as it may backtrack) solution that comes to mind is to write a recursive function, like the following psuedocode

     FindAdjacent(x, y)
           if (matrix[x-1][y-1] == matrix[x][y])
                return 1 + FindAdjacent(x-1,y-1);
           .. Repeat for all 7 other adjacent locations (-1, +0) (+0, -1) (+1, -1) (-1, +1) (+1, +1) (+1, 0) (0, +1)
           else return 1;
    

    This routine would, given a coordinate x,y, return the of symbols around it in a ‘blob’.
    Note: This also means grouping of symbols such as 3 in a row, with 1 next to it in a column below.

    If you were to call this once for every location in the matrix and see if the returned value once all recursive levels return is >= k, that might solve your problem. Remember to do bounds checking so you do not check matrix[-1][-1] or anything.

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

Sidebar

Related Questions

I need to write java generic method that gets no parameter and returns a
I am trying to write a method in Java that accepts a string as
Imagine, I want to write a useless method called: isInstanceof that returns a boolean
I want to write a method in Java that verifies that some conditions hold
In the JSNI example to call a Java method from Javascript, they write this:
I'm using Java 6. As the question states, how would I write a method
i write a method that loops through an array of buttons and checks if
Is there a easy way to skip the readLine() method in java if it
I've been trying to write some very fast Java code that has to do
For a homework problem, I need to write a Java method to find the

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.