对象已移动

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

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
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
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