对象已移动

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

New tool offers direct lighting control for photographs using 3D scene modeling
Softwares

New tool offers direct lighting control for photographs using 3D scene modeling

by admin
August 3, 2025
Laravel ONDC Connector – Webkul Blog
Softwares

Laravel ONDC Connector – Webkul Blog

by admin
August 2, 2025
The hidden crisis behind AI’s promise: Why data quality became an afterthought
Softwares

The hidden crisis behind AI’s promise: Why data quality became an afterthought

by admin
July 31, 2025
Lazarus Group hackers increase open-source weaponisation
Softwares

Lazarus Group hackers increase open-source weaponisation

by admin
July 30, 2025
The Worst Career Advice Right Now: “Don’t Learn to Code” [Article]
Softwares

The Worst Career Advice Right Now: “Don’t Learn to Code” [Article]

by admin
August 1, 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
Instagram Adds New Teleprompter Tool To Edits

Instagram Adds New Teleprompter Tool To Edits

June 11, 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
The hidden crisis behind AI’s promise: Why data quality became an afterthought

The hidden crisis behind AI’s promise: Why data quality became an afterthought

July 31, 2025
TikTok Publishes Report on Top UK Product Trends

TikTok Publishes Report on Top UK Product Trends

August 3, 2025
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Abbotsford, B.C., denies permit for MAGA singer

Abbotsford, B.C., denies permit for MAGA singer

August 2, 2025
Spotify Stock Dips On Q2 Earnings Miss, Focus On Ads Business

Spotify Stock Dips On Q2 Earnings Miss, Focus On Ads Business

July 29, 2025
Ultra-Mini Qi2 Magnetic Power Bank with Kickstand from Baseus is now available on Amazon

Ultra-Mini Qi2 Magnetic Power Bank with Kickstand from Baseus is now available on Amazon

July 30, 2025
Ozzy Osbourne’s Cutest Family Photos with Kids and Grandchildren

Ozzy Osbourne’s Cutest Family Photos with Kids and Grandchildren

August 4, 2025
Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister

Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister

August 4, 2025
How Much Money the Late Actress Made – Hollywood Life

How Much Money the Late Actress Made – Hollywood Life

August 4, 2025
AI Prompts That Go Beyond Content Creation

AI Prompts That Go Beyond Content Creation

August 4, 2025
Photos + Review — My Chemical Romance Bring the Heat in Arlington

Photos + Review — My Chemical Romance Bring the Heat in Arlington

August 3, 2025
Chris Meloni Teases Law & Order: SVU Appearance: ‘Hangin With Friends’

Chris Meloni Teases Law & Order: SVU Appearance: ‘Hangin With Friends’

August 3, 2025
Awesome JAWS Poster Art From Artist Tyler Stout Pays Tribute To Quint — GeekTyrant

Awesome JAWS Poster Art From Artist Tyler Stout Pays Tribute To Quint — GeekTyrant

August 3, 2025
Epson Pro Cinema LS9000: Affordable 4K 120Hz Laser Projector For Gaming And Home Theater

Epson Pro Cinema LS9000: Affordable 4K 120Hz Laser Projector For Gaming And Home Theater

August 3, 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

  • Ozzy Osbourne’s Cutest Family Photos with Kids and Grandchildren
  • Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister
  • How Much Money the Late Actress Made – Hollywood Life
  • 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