对象已移动

可在此处找到该文档 Check if there exists any subarray with the given conditions – 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 there exists any subarray with the given conditions

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


Given two integers N and X. Then the duty is to return YES or NO by checking whether or not there exists a subarray in any permutation of size N such that it comprises a subarray, the place A*B is the same as the X. Right here A and B denote the variety of parts in sub-array and the primary ingredient of sorted subarray respectively.

Examples:

Enter: N = 5, X = 3
Output: YES
Rationalization: Thought-about the permutation is: {5, 2, 1, 3, 4}. Take the sub-array {A4. . . .A4} = { 3 }. Then A = 1 (As just one ingredient is there), B = 3 (If the sub-array is sorted then first ingredient of that sub-array will probably be 3). So, A * B = 1 * 3 = 3, Which is the same as Y. Subsequently, output is YES.

Enter: N = 7, X = 56
Output: NO
Rationalization: It may be verified that no permutation of size N exists such that, It provides worth of A * B as 56. Subsequently, output is NO.

Method: To resolve the issue observe the under thought:

The issue is predicated on Grasping logic and remark primarily based. It may be solved by implementing these observations by implementing them in a code. The remark is, there’ll certainly exist a subarray if the situation (X % i == 0 && (X / i) ≥ 1 && (( X /  i) ≤ N – i + 1) efficiently meet, the place i is the present ingredient.

Under are the steps for the above strategy:

  • Create a Boolean Flag and mark it as False initially.  
  • Run a for loop from i = 1 to i ≤ N and observe the below-mentioned steps beneath the scope of the loop:
    •  If (X % i == 0 && (X / i) ≥ 1 && (( X /  i) ≤ N – i + 1)  is true then mark the flag as true and break the loop.
  • Test if the flag is true, print YES else, print NO.

Under is the code to implement the strategy:

Java

import java.util.*;

  

public class GFG {

  

    

    public static void predominant(String[] args)

    {

  

        

        int N = 5;

        lengthy X = 3;

        Boolean Flag = false;

  

        

        SubArrayExists(N, X, Flag);

    }

  

    

    

    static void SubArrayExists(int N, lengthy X, boolean Flag)

    {

  

        

        

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

  

            

            if (X % i == 0 && (X / i) >= 1

                && ((X / i) <= N - i + 1)) {

  

                

                

                Flag = true;

                break;

            }

        }

  

        System.out.println(Flag ? "YES" : "NO");

    }

}

Time Complexity: O(N)
Auxiliary Area: O(1), As no further area is used.



Source link

Tags: Checkconditionsexistssubarray
Previous Post

8 Keys for Effective Online Reputation Management [Infographic]

Next Post

Fujifilm Instax Mini 12 arrives with a tweaked design and new features

Related Posts

Minor update(4) for Vivaldi Android Browser 7.4
Softwares

Minor update(4) for Vivaldi Android Browser 7.4

by admin
June 21, 2025
How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025
Softwares

How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025

by admin
June 22, 2025
10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy
Softwares

10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy

by admin
June 20, 2025
User Guide For CS-Cart Product Search By Barcode
Softwares

User Guide For CS-Cart Product Search By Barcode

by admin
June 18, 2025
Open Talent platforms emerging to match skilled workers to needs, study finds
Softwares

Open Talent platforms emerging to match skilled workers to needs, study finds

by admin
June 16, 2025
Next Post
Fujifilm Instax Mini 12 arrives with a tweaked design and new features

Fujifilm Instax Mini 12 arrives with a tweaked design and new features

Your Spring Horoscope for Energy, Opportunity, and Love

  • Trending
  • Comments
  • Latest
Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

October 8, 2023
Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

January 21, 2024
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Guide for Bagisto Quick Commerce

Guide for Bagisto Quick Commerce

October 16, 2024
A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

July 2, 2022
8BitDo Retro Mechanical Keyboard C64 Review

8BitDo Retro Mechanical Keyboard C64 Review

March 24, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Gabby Logan shares emotional family update in rare post with daughter Lois

Gabby Logan shares emotional family update in rare post with daughter Lois

September 25, 2024
Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

June 23, 2025
Google adds AI features to Chromebook Plus devices

Google adds AI features to Chromebook Plus devices

June 23, 2025
Generations: The Legacy Teasers on SABC1 June

Generations: The Legacy Teasers on SABC1 June

June 23, 2025
‘Elio’ Had Pixar’s Worst Box Office Opening Weekend Ever

‘Elio’ Had Pixar’s Worst Box Office Opening Weekend Ever

June 23, 2025
Love Island Season 7 Recap: Week 3 Twists Amid Casa Amor (Updating Daily)

Love Island Season 7 Recap: Week 3 Twists Amid Casa Amor (Updating Daily)

June 23, 2025
Is ChatGPT Catching Google on Search Activity? [Infographic]

Is ChatGPT Catching Google on Search Activity? [Infographic]

June 23, 2025
Looking back on the early days of LGBTQ2 rock – National

Looking back on the early days of LGBTQ2 rock – National

June 23, 2025
Lesser-Known Movie Facts You Might Not Know

Lesser-Known Movie Facts You Might Not Know

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

  • Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced
  • Google adds AI features to Chromebook Plus devices
  • Generations: The Legacy Teasers on SABC1 June
  • 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