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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:11:52+00:00 2026-06-02T11:11:52+00:00

Given an array of values, I want to determine if its an increasing or

  • 0

Given an array of values, I want to determine if its an increasing or decreasing array. Of course this is trivial if we want to detect only Monotone Increasing/Decreasing. But if we have an array like this:

3, 3.2, 3.4, 3.3, 3.4, 3.7, 4.2, 4.8

It is indeed an increasing array, but not monotone because for i=3 we have 3.3<3.4

Also, a single check between first and last index is not an option for me, as I may be working with angles, and I could complete more than a single circle:

270º, 290º, 315º, 345º, 5º

I would say that a clockwise is increasing too, despite 5º<270º

Also, if I’m defining angles from 0 to 180 and then -180 to 0 instead of 0 to 360, this is again a problem:

170º, 175º, 180º, -175º, -170º is again increasing for me.

I want to write this for C++, but what matters to me is the algorithm to use. Any idea?

  • 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-02T11:11:55+00:00Added an answer on June 2, 2026 at 11:11 am

    Use linear regression. Based on the resulting slope you can decide whether it’s increasing or decreasing.

    linear regression example from wikipedia

    As for the cyclic case: I would simply move the “negative” elements in front of the list and then do the test…

    Note: for special cases like 5 4 3 2 1 1000 this will still tell you that it’s increasing, but it’s hard to give an exact answer for your question as the definition of “increasing” is quite fuzzy. (You might want to filter out some crazy values?)

    Another simple approach would be to count the number of increases and decreases between adjacent elements, but in this case 10 11 12 13 14 0 1 2 3 4 would be clearly increasing (which might be the right answer, it’s hard to tell..)

    Without knowing more of what you’re trying to achieve it’s hard to give a good answer.

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

Sidebar

Related Questions

Given an array of values, I want to find the total score, where the
i want to store some element String.XML's array. Values are given bellow <string-array name=values>
Given an array with n values, for example: $arr[] = 'ABCDEFABC'; $arr[] = 'ABCDEFDEF';
I have an array with allowed values and an array with given values. Howto
You're given an array of size n, containing arbitrary boolean values. What is the
I have an array of ints like this: [32,128,1024,2048,4096] Given a specific value, I
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
Given a string of pipe-separated values (call it $psv ), I want to be
I want to receive an array that contains all the h1 tag values from
I have a 2-d array for which I want to detect all locally maximal

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.