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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:56:57+00:00 2026-05-17T20:56:57+00:00

given is any sequence of integers like 23 7 13 4 8 6 .

  • 0

given is any sequence of integers like 23 7 13 4 8 6. I want to detect local minima and maxima with the following rules:

  • the first number in the sequence is a local minimum when the following number is greater
  • the last number in the sequence is a local minimum when the previous number is greater
  • a number in the sequence is a local minimum when it is smaller than the previous and the following number

I can use the methods hasNextInt and getNextInt.

Currently I am thinking about the algorithm. But I am not sure whether I understand the logic. First I build a tuple and compare its numbers. E.g. I compare 23 and 7. 7 is the local minimum. What would I do then? Build a triple? But what numbers has that triple, 23 7 13 or 13 4 8? I am not sure.

Any ideas?

Update:

Let’s say we store the left neighbour and the number in the middle of three numbers:

left    middle    current

0        0         23

23       0         7

23       7         13 <- you have a triple, compare => minimum 7

What would happen then? Set the vars to 0 and start with the next number 4? Or store 7 in left, 13 in the middle to have 4 as current?

Update (this code seems to work):

    int left   = 0;
    int center = 0;
    while(hasNextInt()){
        int current = getNextInt();

        if((left != 0) && (center != 0)){
            if(current > center && center < left){
                System.out.println("Min: "+center);
                left = center; center = current;
            }else{
                left = center; center = current;
            }
        }else if((left != 0) && (center == 0)){
            if(left < current){
                System.out.println("Min: "+left);
                center = current;
            }else{
                center = current;
            }
        }else if((left == 0) && (center == 0)){
            left = current;
        }
    }

    if(left > center){
        System.out.println("Min: "+center);
    }

Thanks for your help!

  • 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-05-17T20:56:57+00:00Added an answer on May 17, 2026 at 8:56 pm

    What you have there looks like a good start.

    However, only looking at tuples will no be enough, because you must look at three numbers to detect a local minimum – so you will have to extend your algorithm.

    To understand how to do this, try to work a simple example on paper. How would you go about manually finding the local minima? Can you do something similar in your program?

    Feel free to post an updated version of your program (by editing the question, adding the new code to the bottom), then we can help if you are still stuck.

    Answer to your edit:

    What would happen then? Set the vars
    to 0 and start with the next number 4?
    Or store 7 in left, 13 in the middle
    to have 4 as current?

    You cannot just set everything to 0; you still need the last two numbers of your triple to start the next triple, because your triples behave like a windows sliding over the list of numbers (this is often referred to as a “sliding window” technique, as many algorithms use it).

    You can copy the numbers to their new variables manually.

    For more elegance, you could implement this in a separate “Triplet” class. Ideas to consider: That class could check for minima, and let you add a new number, automatically “pushing out” the oldest number.

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

Sidebar

Related Questions

I'm trying to print in the screen this, given any number like 12: 0+12
given any number, what's the best way to determine it is even? how many
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as
For any given type i want to know its default value. In C#, there
Given an unsorted sequence of integers that flows into your program as a stream.
Using Groovy, I'd like to generate a random sequence of characters from a given
Given a starting number, imagine an infinite sequence of its successive halves. 1, 0.5,
Given the following question, Given an array of integers A of length n, find
You are given two sorted integer arrays, which have some common integers. Any common
Given a sequence of 16 bits, I want to recursively reverse these bits. For

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.