对象已移动

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

Fixes, Polish, and security updates – Vivaldi Browser snapshot 3813.3
Softwares

Fixes, Polish, and security updates – Vivaldi Browser snapshot 3813.3

by admin
September 19, 2025
Fintech Software Development in 2025: Your Complete Guide
Softwares

Fintech Software Development in 2025: Your Complete Guide

by admin
September 20, 2025
User Guide for Odoo Zoho Analytics Connector
Softwares

User Guide for Odoo Zoho Analytics Connector

by admin
September 16, 2025
30+ Best Business & Corporate Report Templates for InDesign & Photoshop in 2025 — Speckyboy
Softwares

30+ Best Business & Corporate Report Templates for InDesign & Photoshop in 2025 — Speckyboy

by admin
September 18, 2025
Software tool turns everyday objects into animated, eye-catching displays—without electronics
Softwares

Software tool turns everyday objects into animated, eye-catching displays—without electronics

by admin
September 17, 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
I Only Have More Questions After Another Bizarre Outing With The Harrigans

I Only Have More Questions After Another Bizarre Outing With The Harrigans

April 20, 2025
Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

April 4, 2025
Google’s AI Ambitions An ‘Existential Crisis’ For News Online

Google’s AI Ambitions An ‘Existential Crisis’ For News Online

September 6, 2025
Ecca Vandal’s “CRUISING TO SELF SOOTHE” video is an ode to skate culture

Ecca Vandal’s “CRUISING TO SELF SOOTHE” video is an ode to skate culture

March 10, 2025
Easy Blueberry Scones (With Frozen Blueberries)

Easy Blueberry Scones (With Frozen Blueberries)

April 10, 2025
Instagram Adds New Teleprompter Tool To Edits

Instagram Adds New Teleprompter Tool To Edits

June 11, 2025
Acyan's "Ghost Town" EP Is Bass Music Storytelling at Its Most Ominous

Acyan's "Ghost Town" EP Is Bass Music Storytelling at Its Most Ominous

May 18, 2025
The Most Visited Websites in the World [Infographic]

The Most Visited Websites in the World [Infographic]

May 12, 2025
The ‘Lego Batman’ Devs Want to Make a New, Definitive Bat-Game

The ‘Lego Batman’ Devs Want to Make a New, Definitive Bat-Game

September 20, 2025
Natalie Wood’s lookalike daughter and granddaughter stun in new photos inspired by the late star

Natalie Wood’s lookalike daughter and granddaughter stun in new photos inspired by the late star

September 20, 2025
Win An Iconic Luxury Watch With The Premium Time Company

Win An Iconic Luxury Watch With The Premium Time Company

September 20, 2025
Alabama Barker Reveals She Was Pregnant But ‘Lost’ The Baby In Deleted TikTok! Oh No!

Alabama Barker Reveals She Was Pregnant But ‘Lost’ The Baby In Deleted TikTok! Oh No!

September 20, 2025
Inside the Rebuild of Amnesia’s Legendary Ibiza Sound System

Inside the Rebuild of Amnesia’s Legendary Ibiza Sound System

September 20, 2025
Inside Matthew McConaughey’s ‘Poems & Prayers’ revival book tour

Inside Matthew McConaughey’s ‘Poems & Prayers’ revival book tour

September 20, 2025
See the Credits and Lyrics to Aerosmith’s New Song With Yungblud

See the Credits and Lyrics to Aerosmith’s New Song With Yungblud

September 19, 2025
The best live TV streaming services to cut cable in 2025

The best live TV streaming services to cut cable in 2025

September 19, 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

  • The ‘Lego Batman’ Devs Want to Make a New, Definitive Bat-Game
  • Natalie Wood’s lookalike daughter and granddaughter stun in new photos inspired by the late star
  • Win An Iconic Luxury Watch With The Premium Time Company
  • 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