Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

jumping sequence java boolean values

// Program for Jolly Jumper Sequence
import java.util.*;
 
class GFG
{
 
// Function to check whether given sequence
// is Jolly Jumper or not
static boolean isJolly(int a[], int n)
{
    // Boolean vector to diffSet set of differences.
    // The vector is initialized as false.
    boolean []diffSet = new boolean[n];
 
    // Traverse all array elements
    for (int i = 0; i < n - 1 ; i++)
    {
        // Find absolute difference
        // between current two
        int d = Math.abs(a[i] - a[i + 1]);
 
        // If difference is out of range or repeated,
        // return false.
        if (d == 0 || d > n - 1 ||
            diffSet[d] == true)
            return false;
 
        // Set presence of d in set.
        diffSet[d] = true;
    }
    return true;
}
 
// Driver Code
public static void main(String[] args)
{
    int a[] = {11, 7, 4, 2, 1, 6};
    int n = a.length;
    if(isJolly(a, n))
        System.out.println("Yes");
    else
        System.out.println("No");
}
}
 
// This code is contributed by Rajput-Ji
Comment

PREVIOUS NEXT
Code Example
Java :: print max activity by greedy technique in java 
Java :: java.lang.ArrayIndexOutOfBoundsException: 4 
Java :: Example of "this" : to invoke current class method 
Java :: differance entre appel implcite et explicite en java 
Java :: newinstance in java giving exception 
Java :: viewResolver 
Java :: Add an element at a specified position in an ArrayList 
Java :: string in java 
Java :: testng with cucumber 
Java :: odd numbers in java 
Java :: bufferedreader 
Java :: java find largest number in list 
Java :: java check if class is subclass 
Java :: annotation spring notnull 
Java :: how to call a void method from another class in java 
Java :: convert python code to java 
Java :: calling a method in java 
Java :: java coding standards for classes 
Java :: what to do in minecraft 
Java :: /bin/sh 1 java not found docker 
Java :: bukkit e.getCurrentItem() bytes? 
Sql :: mysql disable foreign key checks 
Sql :: postgresql find biggest table 
Sql :: redshift running queries 
Sql :: psql uri example 
Sql :: oracle create table comment 
Sql :: how to restart mysql in linux 
Sql :: oracle to_timestamp 
Sql :: mysql add column if not exists 
Sql :: postgres delete from where date is greater than specific date 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =