对象已移动

可在此处找到该文档 Check if given Array is Monotonic – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Check if given Array is Monotonic

by admin
3 years ago
in Softwares
Best Coding Practices For Rest API Design
Share on FacebookShare on Twitter


Given an array arr[] containing N integers, the duty is to examine whether or not the array is monotonic or not (monotonic means both the array is in growing order or in reducing order).

Examples:

Enter: arr[] = {1, 2, 2, 3}
Output: Sure
Rationalization: Right here 1 < 2 <= 2 < 3. 
The array is in growing order. Due to this fact it’s monotonic.

Enter: arr[] =  {6, 5, 4, 3}
Output: Sure
Rationalization: Right here 6 > 5 > 4 > 3. 
The array is in reducing order. So it’s monotonic.

Enter: arr[] = {1, 5, 2}
Output: No
Rationalization: Right here 1 < 5 > 2. The array is neither growing nor reducing. 
So the array just isn’t monotonic

 

Strategy: The issue will be solved by checking if the array is in growing order or in reducing order. This may be simply accomplished within the following manner:

  • If for every i in vary [0, N-2], arr[i] ≥  arr[i+1] the array is in reducing order.
  • If for every i in vary [0, N-2], arr[i] ≤ arr[i+1], the array is in growing order.

Comply with the under steps to unravel the issue:

  • Traverse the array arr[] from i = 0 to N-2 and examine if the array is growing so as
  • Traverse the array arr[] from i = 0 to N-2 and examine if the array is reducing so as
  • If neither of the above two is true, then the array just isn’t monotonic.

Under is the implementation of the above method:

C++

  

#embody <bits/stdc++.h>

utilizing namespace std;

  

bool examine(vector<int>& arr)

{

    int N = arr.measurement();

    bool inc = true;

    bool dec = true;

  

    

    for (int i = 0; i < N - 1; i++) {

  

        

        

        if (arr[i] > arr[i + 1]) {

            inc = false;

        }

    }

  

    

    for (int i = 0; i < N - 1; i++) {

  

        

        

        if (arr[i] < arr[i + 1]) {

            dec = false;

        }

    }

  

    

    return inc || dec;

}

  

int predominant()

{

    vector<int> arr = { 1, 2, 3, 3 };

  

    

    bool ans = examine(arr);

    if (ans)

        cout << "Sure";

    else

        cout << "No";

    return 0;

}

Time Complexity: O(N)
Auxiliary House: O(1)



Source link

Tags: arrayCheckMonotonic
Previous Post

Indulge in walking to pursue a healthy lifestyle – Noise

Next Post

The Beauty Benefits Of Iron For Skin, Hair, And Nails

Related Posts

User Guide for Odoo MultiChannel Email Marketing
Softwares

User Guide for Odoo MultiChannel Email Marketing

by admin
July 6, 2025
Avoid these common platform engineering mistakes
Softwares

Avoid these common platform engineering mistakes

by admin
July 4, 2025
Meta slams ‘incorrect and unlawful’ EU DMA ruling
Softwares

Meta slams ‘incorrect and unlawful’ EU DMA ruling

by admin
July 3, 2025
Best Practices, Tools, xUnit, and NUnit Framework
Softwares

Best Practices, Tools, xUnit, and NUnit Framework

by admin
July 1, 2025
Start up crash fix – Vivaldi iOS Browser snapshot 3737.4
Softwares

Start up crash fix – Vivaldi iOS Browser snapshot 3737.4

by admin
June 30, 2025
Next Post
The Beauty Benefits Of Iron For Skin, Hair, And Nails

The Beauty Benefits Of Iron For Skin, Hair, And Nails

Prince’s 1985 Syracuse Purple Rain Show Will Finally be Released

Prince's 1985 Syracuse Purple Rain Show Will Finally be Released

  • Trending
  • Comments
  • Latest
All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

June 28, 2025
‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

June 22, 2021
How to integrate Odoo with ReactJs frontend

How to integrate Odoo with ReactJs frontend

October 7, 2024
Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

July 3, 2025
Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

December 7, 2024
Jane Withers, child actor and commercial star, dies at 95 – National

Jane Withers, child actor and commercial star, dies at 95 – National

August 10, 2021
18 Best Political Series on Netflix, Ranked

18 Best Political Series on Netflix, Ranked

March 25, 2025
Games teach kids climate action

Games teach kids climate action

January 23, 2024
Hip-Hop Artists We Lost in 2025

Hip-Hop Artists We Lost in 2025

July 6, 2025
$49 Align Styles and More Steals Starting at $19

$49 Align Styles and More Steals Starting at $19

July 6, 2025
Queen Mary of Denmark stuns in the staple of the summer

Queen Mary of Denmark stuns in the staple of the summer

July 6, 2025
Countdown Episode 5 Release Date, Time, Where to Watch

Countdown Episode 5 Release Date, Time, Where to Watch

July 6, 2025
App Cast: Android’s Rival To Apple’s Handoff Feature Spotted

App Cast: Android’s Rival To Apple’s Handoff Feature Spotted

July 6, 2025
Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

July 5, 2025
Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

July 5, 2025
Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

July 5, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Hip-Hop Artists We Lost in 2025
  • $49 Align Styles and More Steals Starting at $19
  • Queen Mary of Denmark stuns in the staple of the summer
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life