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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:14:56+00:00 2026-06-17T18:14:56+00:00

I have an integer array with five values, sorted in ascending order with no

  • 0

I have an integer array with five values, sorted in ascending order with no duplicates. I want to check if three of the five values that are in the array meet the requirement that they are in a sequence but don’t all have to.

If three of the group of numbers below are in the array of five numbers the requirement is met:

(1, 2, 3, 4)
or
(5, 6, 7, 8)
or
(9, 10, 11, 12)
etc.

So the following arrays return true:

EXAMPLES:
(1, 2, 3, 18, 40)
or
(2, 3, 4, 20, 34)
or
(1, 3, 4, 7, 12)
or
(9, 11, 12, 31, 51)

While the following arrays return false:

EXAMPLES:
(3, 4, 5, 11, 29)
or
(15, 16, 17, 33, 42)
etc.

The “rule” is that three numbers in the array of five numbers must be within the respective range, 1, 2, 3, 4 or 5, 6, 7, 8 etc. but I don’t know how to go over this

Could someone please help me with this?

I will be forever grateful!

EDIT (since as a new user I can’t post an answer to my own question so soon):

Okay, I have found a partial answer: First I check if three cards have the same rank.

I check if cards 1 to 3 have the same rank. If not, I check if cards 2 to 4 have the same rank. If not, I check if cards 3 to 5 have the same rank. Here is my code:

// check
if (tempArray[0] == (tempArray[1] - 1)) {
    System.out.println("1. and 2. card match");
    if (tempArray[1] == (tempArray[2] - 1)) {
        System.out.println("2. and 3. card match");
        // three cards of same rank, starting from the first
        if (...) {
            isThreeOfAKind = true;
        }
    }
} else {
    System.out.println("1. and 2. card DO NOT match");
    // toak could start from the second card
    if (tempArray[1] == (tempArray[2] - 1)) {
        System.out.println("2. and 3. card match");
        if (tempArray[2] == (tempArray[3] - 1)) {
            System.out.println("3. and 4. card match");
            // three cards of same rank, starting from the second
            if (...) {
                isThreeOfAKind = true;
            }
        }
    } else {
        // toak could start from the third card
        System.out.println("2. and 3. card DO NOT match");
        if (tempArray[2] == (tempArray[3] - 1)) {
            System.out.println("3. and 4. card match");
            if (tempArray[3] == (tempArray[4] - 1)) {
                System.out.println("4. and 5. card match");
                // three cards of same rank, starting from the third
                if (...) {
                    isThreeOfAKind = true;
                }
            }
        }
    }
}

Now you notice that I left out the if clauses. There I have to check if the numbers are within the range (1-4, 5-8, 9-12, etc.) but I have no idea.! But the code is still faulty because for example 1, 3, 4 are not recognised as the same ranks even though it’s valid

  • 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-17T18:14:58+00:00Added an answer on June 17, 2026 at 6:14 pm
    public boolean check3InARow(int[] array) {
      int currentResult = (array[0] - 1) / 4;
      int countCurrentResult = 1;
      for (int i=1; i < array.length; i++) {
        if (((array[i] - 1) / 4) == currentResult) {
          countCurrentResult++
          if (countCurrentResult == 3) return true;
        } else {
          currentResult = (array[i] - 1) / 4;
          countCurrentResult = 1
        }
      }
      return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sorted integer array on the device, e.g.: [0,0,0,1,1,2,2] And I want
I have an integer array like {1,2,3,4,5,0,0,0,0,0,2,3,4,5,7,8,0,0,0,0,0,1} I want to check if the array's
This should be simple. I have an integer array that I want to encode
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I have an integer array: a=[3,4,5,6,7]; I want to convert it to a binary
Let's I have a method to remove duplicates in an integer Array public int[]
I have a program that has to declare a huge integer array of the
I have a 2D-array that I want to sort based on the second column.
i have integer pixel array of an image with values like -1100791, -16777056 and
I have an integer array of length 900 that contains only binary data [0,1].

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.