对象已移动

可在此处找到该文档 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

Windows’ infamous ‘blue screen of death’ will soon turn black
Softwares

Windows’ infamous ‘blue screen of death’ will soon turn black

by admin
June 28, 2025
User Guide for Unopim Odoo Connector
Softwares

User Guide for Unopim Odoo Connector

by admin
June 27, 2025
Warp 2.0 evolves its terminal experience into an Agentic Development Environment
Softwares

Warp 2.0 evolves its terminal experience into an Agentic Development Environment

by admin
June 25, 2025
10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy
Softwares

10+ Best Text Animation Presets & Templates for Premiere Pro — Speckyboy

by admin
June 29, 2025
Huawei Cloud rolls out Pangu Models 5.5 to cover more industries
Softwares

Huawei Cloud rolls out Pangu Models 5.5 to cover more industries

by admin
June 24, 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
User Manual for Odoo Docx Report Builder

User Manual for Odoo Docx Report Builder

November 30, 2024
Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

January 11, 2024
Torras Ostand O3 Air iPhone case review – It runs rings around other cases

Torras Ostand O3 Air iPhone case review – It runs rings around other cases

May 21, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Over 140 People ‘Pricked’ With Syringes at Music Festival

Over 140 People ‘Pricked’ With Syringes at Music Festival

June 24, 2025
The Best Madras Shirt Brands For Men: Summer 2021 Edition

The Best Madras Shirt Brands For Men: Summer 2021 Edition

July 20, 2021
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
A Friend of the Family: Where Is Jan Broberg Now?

A Friend of the Family: Where Is Jan Broberg Now?

October 14, 2022
Korean & Spanish Shows Win Big At Italian Global Series Festival

Korean & Spanish Shows Win Big At Italian Global Series Festival

June 29, 2025
‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

‘Ironheart’ Makes a Major Pivot From the Comics With This One Change

June 29, 2025
WhatsApp Banned From U.S. House Devices Over Security Concerns

WhatsApp Banned From U.S. House Devices Over Security Concerns

June 29, 2025
Kylie Jenner Fuels Hailey & Justin Bieber Divorce Rumors With Telling Detail In Group Chat!

Kylie Jenner Fuels Hailey & Justin Bieber Divorce Rumors With Telling Detail In Group Chat!

June 29, 2025
Public Enemy Put Tech, Ageism In The Crosshairs On Surprise New LP

Public Enemy Put Tech, Ageism In The Crosshairs On Surprise New LP

June 29, 2025
Warner Bros. Gives Up on ‘Akira’ Remake, But Hollywood Won’t

Warner Bros. Gives Up on ‘Akira’ Remake, But Hollywood Won’t

June 28, 2025
Public Rec Men’s Pants Review (Are They Worth It?)

Public Rec Men’s Pants Review (Are They Worth It?)

June 29, 2025
Hulu Schedule June 30 – July 6, 2025: New TV Shows & Movies Being Added

Hulu Schedule June 30 – July 6, 2025: New TV Shows & Movies Being Added

June 28, 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

  • Korean & Spanish Shows Win Big At Italian Global Series Festival
  • ‘Ironheart’ Makes a Major Pivot From the Comics With This One Change
  • WhatsApp Banned From U.S. House Devices Over Security Concerns
  • 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