对象已移动

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

How to Be the Leader Your Web Design Clients Need — Speckyboy
Softwares

How to Be the Leader Your Web Design Clients Need — Speckyboy

by admin
August 4, 2025
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
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
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
Diddy’s Ex-Girlfriend Wants Him Released Ahead Of Sentencing

Diddy’s Ex-Girlfriend Wants Him Released Ahead Of Sentencing

August 4, 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
How to Be the Leader Your Web Design Clients Need — Speckyboy

How to Be the Leader Your Web Design Clients Need — Speckyboy

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

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

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

  • Diddy’s Ex-Girlfriend Wants Him Released Ahead Of Sentencing
  • Ozzy Osbourne’s Cutest Family Photos with Kids and Grandchildren
  • Liam Neeson, Pamela Anderson Get Nod From Natasha Richardson’s Sister
  • 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