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

AI updates from the past week: IBM watsonx Orchestrate updates, web search in Anthropic API, and more — May 9, 2025
Softwares

AI updates from the past week: IBM watsonx Orchestrate updates, web search in Anthropic API, and more — May 9, 2025

by admin
May 11, 2025
Unlocking the Future of Finance
Softwares

Unlocking the Future of Finance

by admin
May 8, 2025
Address bar tweaks – Vivaldi Browser snapshot 3683.4
Softwares

Address bar tweaks – Vivaldi Browser snapshot 3683.4

by admin
May 7, 2025
A faster, sleeker JavaScript experience
Softwares

A faster, sleeker JavaScript experience

by admin
May 10, 2025
How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy
Softwares

How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy

by admin
May 6, 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
Cameron Monaghan Discusses Erotic Thriller

Cameron Monaghan Discusses Erotic Thriller

January 13, 2022
Doctor Strange: 12 Best Comic Issues Of The 1990s

Doctor Strange: 12 Best Comic Issues Of The 1990s

December 11, 2021
Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

March 1, 2024
Best travel cameras 2023

Best travel cameras 2023

December 13, 2023
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Best Cryptocurrency Wallets Comparison | SCAND Blog

Best Cryptocurrency Wallets Comparison | SCAND Blog

July 30, 2022
Trends in Mobile App Development

Trends in Mobile App Development

December 1, 2021
The Best Crime Shows on Netflix

The Best Crime Shows on Netflix

May 27, 2023
Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment

Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment

May 12, 2025
Niall Horan Returning to The Voice as Coach

Niall Horan Returning to The Voice as Coach

May 12, 2025
Kate Middleton makes huge announcement with the help of Prince William in new teaser video

Kate Middleton makes huge announcement with the help of Prince William in new teaser video

May 12, 2025
Apple reportedly plans to hike prices of upcoming iPhones

Apple reportedly plans to hike prices of upcoming iPhones

May 12, 2025
Who Is Shane Lowry’s Wife? Wendy’s Job & Kids

Who Is Shane Lowry’s Wife? Wendy’s Job & Kids

May 12, 2025
The Best Luxury Sportswear Brands for Men in 2025

The Best Luxury Sportswear Brands for Men in 2025

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

The Most Visited Websites in the World [Infographic]

May 12, 2025
I’m Frustrated With How Many New Characters Played A Critical Role At The End Of This Episode

I’m Frustrated With How Many New Characters Played A Critical Role At The End Of This Episode

May 11, 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

  • Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment
  • Niall Horan Returning to The Voice as Coach
  • Kate Middleton makes huge announcement with the help of Prince William in new teaser video
  • 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.

slot games login