content stringlengths 219 31.2k | complexity stringclasses 5
values | file_name stringlengths 6 9 | complexity_ranked float64 0.1 0.9 |
|---|---|---|---|
// Java program to check if all leaf nodes are at
// same level of binary tree
import
java.util.*;
// User defined node class
class
Node {
int
data;
Node left, right;
// Constructor to create a new tree node
Node(
int
key) {
int
data = key;
left = right =
null
;
}
}
class
GFG {
// return tru... | n | 420.java | 0.5 |
// Java program to check if there exist an edge whose
// removal creates two trees of same size
class
Node
{
int
key;
Node left, right;
public
Node(
int
key)
{
this
.key = key;
left = right =
null
;
}
}
class
Res
{
boolean
res =
false
;
}
class
BinaryTree
{
Node root;
// To calculat... | n | 422.java | 0.5 |
// Java program to check whether a given
// Binary Tree is Perfect or not
class
GfG {
/* Tree node structure */
static
class
Node
{
int
key;
Node left, right;
}
// Returns depth of leftmost leaf.
static
int
findADepth(Node node)
{
int
d =
0
;
while
(node !=
null
)
{
d++;
node = node.left;
}
re... | n | 424.java | 0.5 |
// Java program to check if binay tree is full or not
/* Tree node structure */
class
Node
{
int
data;
Node left, right;
Node(
int
item)
{
data = item;
left = right =
null
;
}
}
class
BinaryTree
{
Node root;
/* this function checks if a binary tree is full or not */
boolean
isFullTree(Node... | n | 425.java | 0.5 |
//A Java program to check if a given binary tree is complete or not
import
java.util.LinkedList;
import
java.util.Queue;
public
class
CompleteBTree
{
/* A binary tree node has data, a pointer to left child
and a pointer to right child */
static
class
Node
{
int
data;
Node left;
Node right;
// Con... | n | 426.java | 0.5 |
// Java program to check if binary tree
// is subtree of another binary tree
class
Node {
char
data;
Node left, right;
Node(
char
item)
{
data = item;
left = right =
null
;
}
}
class
Passing {
int
i;
int
m =
0
;
int
n =
0
;
}
class
BinaryTree {
static
Node root;
Passing p =
new
... | n | 428.java | 0.5 |
// Java program to see if two trees
// are mirror of each other
// A binary tree node
class
Node
{
int
data;
Node left, right;
public
Node(
int
data)
{
this
.data = data;
left = right =
null
;
}
}
class
BinaryTree
{
Node a, b;
/* Given two trees, return true if they are
mirror of each o... | n | 429.java | 0.5 |
// Java implementation of worst
// case linear time algorithm
// to find k'th smallest element
import
java.util.*;
class
GFG
{
// int partition(int arr[], int l, int r, int k);
// A simple function to find median of arr[]. This is called
// only for an array of size 5 in this program.
static
int
findMedian... | n | 43.java | 0.5 |
// Java implementation to check whether the two
// binary tress are mirrors of each other or not
import
java.util.*;
class
GfG {
// structure of a node in binary tree
static
class
Node
{
int
data;
Node left, right;
}
// Utility function to create and return
// a new node for a binary tree
static
Node n... | n | 430.java | 0.5 |
// Java program to see if two trees are identical
// A binary tree node
class
Node
{
int
data;
Node left, right;
Node(
int
item)
{
data = item;
left = right =
null
;
}
}
class
BinaryTree
{
Node root1, root2;
/* Given two trees, return true if they are
structurally identical */
boolean
i... | n | 431.java | 0.5 |
// Java program to see if there is a root to leaf path
// with given sequence.
public
class
CheckForPath {
// function to check given sequence of root to leaf path exist
// in tree or not.
// index represents current element in sequence of rooth to
// leaf path
public
static
boolean
existPath(Node root,
... | n | 432.java | 0.5 |
// Java program to print cousins of a node
class
GfG {
// A Binary Tree Node
static
class
Node
{
int
data;
Node left, right;
}
// A utility function to create a new Binary
// Tree Node
static
Node newNode(
int
item)
{
Node temp =
new
Node();
temp.data = item;
temp.left =
null
;
temp.right =
n... | n | 433.java | 0.5 |
// Java implementation to print the path from root
// to a given node in a binary tree
import
java.util.ArrayList;
public
class
PrintPath {
// Returns true if there is a path from root
// to the given node. It also populates
// 'arr' with the given path
public
static
boolean
hasPath(Node root, ArrayList<In... | n | 434.java | 0.5 |
// Recursive Java program to print odd level nodes
class
GfG {
static
class
Node {
int
data;
Node left, right;
}
static
void
printOddNodes(Node root,
boolean
isOdd)
{
// If empty tree
if
(root ==
null
)
return
;
// If current node is of odd level
if
(isOdd ==
true
)
System.out.print(root.dat... | n | 435.java | 0.5 |
// Iterative Java program to print odd level nodes
import
java.util.*;
class
GfG {
static
class
Node {
int
data;
Node left, right;
}
// Iterative method to do level order traversal line by line
static
void
printOddNodes(Node root)
{
// Base Case
if
(root ==
null
)
return
;
// Create an empty queu... | n | 436.java | 0.5 |
// Java program to find the all full nodes in
// a given binary tree
public
class
FullNodes {
// Traverses given tree in Inorder fashion and
// prints all nodes that have both children as
// non-empty.
public
static
void
findFullNode(Node root)
{
if
(root !=
null
)
{
findFullNode(root.left);
if
(... | n | 437.java | 0.5 |
// Java implementation to find
// the sum of all the parent
// nodes having child node x
class
GFG
{
// sum
static
int
sum =
0
;
// Node of a binary tree
static
class
Node
{
int
data;
Node left, right;
};
// function to get a new node
static
Node getNode(
int
data)
{
// allocate memory for the n... | n | 438.java | 0.5 |
class
LinkedList {
/* head node of link list */
static
LNode head;
/* Link list Node */
class
LNode
{
int
data;
LNode next, prev;
LNode(
int
d)
{
data = d;
next = prev =
null
;
}
}
/* A Binary Tree Node */
class
TNode
{
int
data;
TNode left, right;
TNode(
int
d)
{
data = d;... | n | 439.java | 0.5 |
// Java Program to find maximum in arr[]
class
Test
{
static
int
arr[] = {
10
,
324
,
45
,
90
,
9808
};
// Method to find maximum in arr[]
static
int
largest()
{
int
i;
// Initialize maximum element
int
max = arr[
0
];
// Traverse array elements from second and
// compare every element with ... | n | 44.java | 0.5 |
// Java program to print BST in given range
// A binary tree node
class
Node {
int
data;
Node left, right;
Node(
int
d) {
data = d;
left = right =
null
;
}
}
class
BinaryTree {
static
Node root;
/* A function that constructs Balanced Binary Search Tree
from a sorted array */
Node sortedAr... | n | 440.java | 0.5 |
// Java program to convert BST to binary tree such that sum of
// all greater keys is added to every key
class
Node {
int
data;
Node left, right;
Node(
int
d) {
data = d;
left = right =
null
;
}
}
class
Sum {
int
sum =
0
;
}
class
BinaryTree {
static
Node root;
Sum summ =
new
Sum();
... | n | 441.java | 0.5 |
// Java program to find minimum value node in Binary Search Tree
// A binary tree node
class
Node {
int
data;
Node left, right;
Node(
int
d) {
data = d;
left = right =
null
;
}
}
class
BinaryTree {
static
Node head;
/* Given a binary search tree and a number,
inserts a new node with the gi... | n | 442.java | 0.5 |
// Java implementation to check if the given array
// can represent Level Order Traversal of Binary
// Search Tree
import
java.util.*;
class
Solution
{
// to store details of a node like
// node's data, 'min' and 'max' to obtain the
// range of values where node's left and
// right child's should lie
stati... | n | 443.java | 0.5 |
// Java Program for finding K-th largest Node using O(1)
// extra memory and reverse Morris traversal.
class
GfG
{
static
class
Node
{
int
data;
Node left, right;
}
// helper function to create a new Node
static
Node newNode(
int
data)
{
Node temp =
new
Node();
temp.data = data;
temp.right =
nul... | n | 445.java | 0.5 |
// Java code to find second largest element in BST
// A binary tree node
class
Node {
int
data;
Node left, right;
Node(
int
d)
{
data = d;
left = right =
null
;
}
}
class
BinarySearchTree {
// Root of BST
Node root;
// Constructor
BinarySearchTree()
{
root =
null
;
}
// funct... | n | 446.java | 0.5 |
// Java program to find k'th largest element in BST
import
java.util.*;
class
GfG {
// A BST node
static
class
Node
{
int
key;
Node left, right;
}
// A function to find
static
int
KSmallestUsingMorris(Node root,
int
k)
{
// Count to iterate over elements till we
// get the kth smallest number
int... | n | 447.java | 0.5 |
// Java program to check if a given array is sorted
// or not.
class
GFG {
// Function that returns true if array is Inorder
// traversal of any Binary Search Tree or not.
static
boolean
isInorder(
int
[] arr,
int
n) {
// Array has one or no element
if
(n ==
0
|| n ==
1
) {
return
true
;
}
for
(
... | n | 449.java | 0.5 |
// Java code to find largest three elements
// in an array
class
PrintLargest
{
/* Function to print three largest elements */
static
void
print3largest(
int
arr[],
int
arr_size)
{
int
i, first, second, third;
/* There should be atleast three elements */
if
(arr_size <
3
)
{
System.out.print(
" In... | n | 45.java | 0.5 |
// Java implementation to count pairs from two
// BSTs whose sum is equal to a given value x
import
java.util.Stack;
public
class
GFG {
// structure of a node of BST
static
class
Node {
int
data;
Node left, right;
// constructor
public
Node(
int
data) {
this
.data = data;
left =
null
;
right = ... | n | 451.java | 0.5 |
// A Java program to remove BST
// keys outside the given range
import
java.math.BigDecimal;
import
java.util.ArrayList;
import
java.util.Arrays;
import
java.util.List;
import
java.util.Scanner;
class
Node
{
int
key;
Node left;
Node right;
}
class
GFG
{
// Removes all nodes having value
// outsi... | n | 452.java | 0.5 |
// Java code to find a pair with given sum
// in a Balanced BST
import
java.util.ArrayList;
// A binary tree node
class
Node {
int
data;
Node left, right;
Node(
int
d)
{
data = d;
left = right =
null
;
}
}
class
BinarySearchTree {
// Root of BST
Node root;
// Constructor
BinarySearch... | n | 453.java | 0.5 |
// Java program to find maximum element in the path
// between two Nodes of Binary Search Tree.
class
Solution
{
static
class
Node
{
Node left, right;
int
data;
}
// Create and return a pointer of new Node.
static
Node createNode(
int
x)
{
Node p =
new
Node();
p . data = x;
p . left = p . right =... | n | 454.java | 0.5 |
// Java program to find pairs with given sum such
// that one element of pair exists in one BST and
// other in other BST.
import
java.util.*;
class
solution
{
// A binary Tree node
static
class
Node
{
int
data;
Node left, right;
};
// A utility function to create a new BST node
// with key as given n... | n | 455.java | 0.5 |
// Java code to add all greater values to
// every node in a given BST
// A binary tree node
class
Node {
int
data;
Node left, right;
Node(
int
d)
{
data = d;
left = right =
null
;
}
}
class
BinarySearchTree {
// Root of BST
Node root;
// Constructor
BinarySearchTree()
{
root =
n... | n | 456.java | 0.5 |
// Java program to find efficient
// solution for the network
import
java.util.*;
class
GFG {
// number of houses and number
// of pipes
static
int
n, p;
// Array rd stores the
// ending vertex of pipe
static
int
rd[] =
new
int
[
1100
];
// Array wd stores the value
// of diameters between two ... | n | 461.java | 0.5 |
// Java program to find maximum number of
// thieves caught
import
java.util.*;
import
java.io.*;
class
GFG
{
// Returns maximum number of thieves
// that can be caught.
static
int
policeThief(
char
arr[],
int
n,
int
k)
{
int
res =
0
;
ArrayList<Integer> thi =
new
ArrayList<Integer>();
ArrayLis... | n | 462.java | 0.5 |
// Java program to find maximum product of
// a subset.
class
GFG {
static
int
minProductSubset(
int
a[],
int
n)
{
if
(n ==
1
)
return
a[
0
];
// Find count of negative numbers,
// count of zeros, maximum valued
// negative number, minimum valued
// positive number and product of
// non-zero nu... | n | 469.java | 0.5 |
// Java program to find maximum product of
// a subset.
class
GFG {
static
int
maxProductSubset(
int
a[],
int
n) {
if
(n ==
1
) {
return
a[
0
];
}
// Find count of negative numbers, count
// of zeros, maximum valued negative number
// and product of non-zero numbers
int
max_neg = Integer.MIN_VAL... | n | 470.java | 0.5 |
// Java program to minimize the
// cost of array minimization
import
java.util.Arrays;
public
class
GFG {
// Returns minimum possible
// sum in array B[]
static
int
minSum(
int
[] A,
int
n) {
int
min_val = Arrays.stream(A).min().getAsInt();
return
(min_val * (n -
1
));
}
// Driver Code
static
pub... | n | 479.java | 0.5 |
// Java program to make GCD
// of array a mutiple of k.
import
java.io.*;
class
GFG
{
static
int
MinOperation(
int
a[],
int
n,
int
k)
{
int
result =
0
;
for
(
int
i =
0
; i < n; ++i)
{
// If array value is not 1
// and it is greater than k
// then we can increase the
// or decrease the rem... | n | 481.java | 0.5 |
// JAVA Code for Find maximum sum possible
// equal sum of three stacks
class
GFG {
// Returns maximum possible equal sum of three
// stacks with removal of top elements allowed
public
static
int
maxSum(
int
stack1[],
int
stack2[],
int
stack3[],
int
n1,
int
n2,
int
n3)
{
int
sum1 =
0
, sum2 =
0
,... | n | 494.java | 0.5 |
// Java program to divide n integers
// in two groups such that absolute
// difference of their sum is minimum
import
java.io.*;
import
java.util.*;
class
GFG
{
// To print vector along size
static
void
printVector(Vector<Integer> v)
{
// Print vector size
System.out.println(v.size());
// Print vec... | n | 496.java | 0.5 |
// Java program to find minimum cost
// to reduce array size to 1,
import
java.lang.*;
public
class
GFG {
// function to calculate the
// minimum cost
static
int
cost(
int
[]a,
int
n)
{
int
min = a[
0
];
// find the minimum using
// for loop
for
(
int
i =
1
; i< a.length; i++)
{
if
(a[i] < ... | n | 500.java | 0.5 |
// Java program to find smallest
// number to find smallest number
// with N as sum of digits and
// divisible by 10^N.
import
java.io.*;
class
GFG
{
static
void
digitsNum(
int
N)
{
// If N = 0 the string will be 0
if
(N ==
0
)
System.out.println(
"0"
);
// If n is not perfectly divisible
// by ... | n | 506.java | 0.5 |
// Java program to find the smallest number that can be
// formed from given sum of digits and number of digits
class
GFG
{
// Function to print the smallest possible number with digit sum 's'
// and 'm' number of digits
static
void
findSmallest(
int
m,
int
s)
{
// If sum of digits is 0, then a number i... | n | 507.java | 0.5 |
// Java program to rearrange characters in a string
// so that no two adjacent characters are same.
import
java.io.*;
import
java.util.*;
class
KeyComparator
implements
Comparator<Key> {
// Overriding compare()method of Comparator
public
int
compare(Key k1, Key k2)
{
if
(k1.freq < k2.freq)
return
1
; ... | n | 508.java | 0.5 |
// Java program to print a string with
// no adjacent duplicates by doing
// minimum changes to original string
import
java.util.*;
import
java.lang.*;
public
class
GfG{
// Function to print simple string
public
static
String noAdjacentDup(String s1)
{
int
n = s1.length();
char
[] s = s1.toCharArray()... | n | 509.java | 0.5 |
// Recursive Java program to search x in array
class
Test
{
static
int
arr[] = {
12
,
34
,
54
,
2
,
3
};
/* Recursive Method to search x in arr[l..r] */
static
int
recSearch(
int
arr[],
int
l,
int
r,
int
x)
{
if
(r < l)
return
-
1
;
if
(arr[l] == x)
return
l;
if
(arr[r] == x)
return
r;
r... | n | 515.java | 0.5 |
// Java program to find missing Number
class
Main {
// Function to ind missing number
static
int
getMissingNo(
int
a[],
int
n)
{
int
i, total;
total = (n +
1
) * (n +
2
) /
2
;
for
(i =
0
; i < n; i++)
total -= a[i];
return
total;
}
/* program to test above function */
public
static
void
m... | n | 517.java | 0.5 |
// Java program to find smallest and second smallest elements
import
java.io.*;
class
SecondSmallest
{
/* Function to print first smallest and second smallest
elements */
static
void
print2Smallest(
int
arr[])
{
int
first, second, arr_size = arr.length;
/* There should be atleast two elements */
if
(a... | n | 524.java | 0.5 |
class
Main
{
/* Function to get index of ceiling
of x in arr[low..high] */
static
int
ceilSearch(
int
arr[],
int
low,
int
high,
int
x)
{
int
i;
/* If x is smaller than or equal to first
element,then return the first element */
if
(x <= arr[low])
return
low;
/* Otherwise, linearly search for cei... | n | 526.java | 0.5 |
// Java program to count occurrences
// of an element
class
Main
{
// Returns number of times x occurs in arr[0..n-1]
static
int
countOccurrences(
int
arr[],
int
n,
int
x)
{
int
res =
0
;
for
(
int
i=
0
; i<n; i++)
if
(x == arr[i])
res++;
return
res;
}
public
static
void
main(String args[])... | n | 528.java | 0.5 |
// Java program to Find the repeating
// and missing elements
import
java.io.*;
class
GFG {
static
void
printTwoElements(
int
arr[],
int
size)
{
int
i;
System.out.print(
"The repeating element is "
);
for
(i =
0
; i < size; i++) {
int
abs_val = Math.abs(arr[i]);
if
(arr[abs_val -
1
] >
0
)
a... | n | 531.java | 0.5 |
// Java program to Find the repeating
// and missing elements
import
java.io.*;
class
GFG {
static
int
x, y;
static
void
getTwoElements(
int
arr[],
int
n)
{
/* Will hold xor of all elements
and numbers from 1 to n */
int
xor1;
/* Will have only single set bit of xor1 */
int
set_bit_no;
int
i; ... | n | 532.java | 0.5 |
// Java program to check fixed point
// in an array using linear search
class
Main
{
static
int
linearSearch(
int
arr[],
int
n)
{
int
i;
for
(i =
0
; i < n; i++)
{
if
(arr[i] == i)
return
i;
}
/* If no fixed point present
then return -1 */
return
-
1
;
}
//main function
public
static
... | n | 533.java | 0.5 |
// java program to find maximum
// element
class
Main
{
// function to find the
// maximum element
static
int
findMaximum(
int
arr[],
int
low,
int
high)
{
int
max = arr[low];
int
i;
for
(i = low; i <= high; i++)
{
if
(arr[i] > max)
max = arr[i];
}
return
max;
}
// main function
pub... | n | 535.java | 0.5 |
// Java program to find a pair with the given difference
import
java.io.*;
class
PairDifference
{
// The function assumes that the array is sorted
static
boolean
findPair(
int
arr[],
int
n)
{
int
size = arr.length;
// Initialize positions of two elements
int
i =
0
, j =
1
;
// Search for a pair
... | n | 537.java | 0.5 |
// JAVA Code for Find Second largest
// element in an array
class
GFG {
/* Function to print the second largest
elements */
public
static
void
print2largest(
int
arr[],
int
arr_size)
{
int
i, first, second;
/* There should be atleast two elements */
if
(arr_size <
2
)
{
System.out.print(
" Inval... | n | 54.java | 0.5 |
/* Java program to find first repeating element in arr[] */
import
java.util.*;
class
Main
{
// This function prints the first repeating element in arr[]
static
void
printFirstRepeating(
int
arr[])
{
// Initialize index of first repeating element
int
min = -
1
;
// Creates an empty hashset
HashSet<In... | n | 541.java | 0.5 |
// Java program to find common elements in three arrays
class
FindCommon
{
// This function prints common elements in ar1
void
findCommon(
int
ar1[],
int
ar2[],
int
ar3[])
{
// Initialize starting indexes for ar1[], ar2[] and ar3[]
int
i =
0
, j =
0
, k =
0
;
// Iterate through three arrays while a... | n | 542.java | 0.5 |
// Java program to find pair with sum closest to x
import
java.io.*;
import
java.util.*;
import
java.lang.Math;
class
CloseSum {
// Prints the pair with sum cloest to x
static
void
printClosest(
int
arr[],
int
n,
int
x)
{
int
res_l=
0
, res_r=
0
;
// To store indexes of result pair
// Initialize le... | n | 544.java | 0.5 |
// Java program to find closest pair in an array
class
ClosestPair
{
// ar1[0..m-1] and ar2[0..n-1] are two given sorted
// arrays/ and x is given number. This function prints
// the pair from both arrays such that the sum of the
// pair is closest to x.
void
printClosest(
int
ar1[],
int
ar2[],
int
m,
i... | n | 545.java | 0.5 |
// Java program to find a pair with a given
// sum in a sorted and rotated array
class
PairInSortedRotated
{
// This function returns true if arr[0..n-1]
// has a pair with sum equals to x.
static
boolean
pairInSortedRotated(
int
arr[],
int
n,
int
x)
{
// Find the pivot element
int
i;
for
(i =
0
;... | n | 547.java | 0.5 |
// Java program to find largest pair sum in a given array
class
Test
{
static
int
arr[] =
new
int
[]{
12
,
34
,
10
,
6
,
40
};
/* Method to return largest pair sum. Assumes that
there are at-least two elements in arr[] */
static
int
findLargestSumPair()
{
// Initialize first and second largest elem... | n | 549.java | 0.5 |
// Java program to find smallest and second smallest elements
import
java.io.*;
class
SecondSmallest
{
/* Function to print first smallest and second smallest
elements */
static
void
print2Smallest(
int
arr[])
{
int
first, second, arr_size = arr.length;
/* There should be atleast two elements */
if
(a... | n | 55.java | 0.5 |
import jdk.nashorn.internal.objects.NativeArray;
import javax.swing.JOptionPane ;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.sql.SQLSyntaxErrorException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;
import static jdk.nashorn.i... | n | 551.java | 0.5 |
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s = new Scanner(System.in);
int n ... | n | 552.java | 0.5 |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package newpackage;
import java.util.*;
/**
*
* @author parpaorsa
*/
public class NewClass {
static Scanner in=new Scanner(Sys... | n | 553.java | 0.5 |
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int n=sc.nextInt();
String s=sc.next();
int sum=0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='+') {
sum++;
}
if(s.charAt(i)=='-'&&sum!=0... | n | 554.java | 0.5 |
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s = new Scanner(System.in);
int n ... | n | 555.java | 0.5 |
//package com.krakn.CF.B1159;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
... | n | 557.java | 0.5 |
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int tmp;
int min=Integer.MAX_VALUE;
for(int i=0;i<n;i++) {
tmp=sc.nextInt();
if(i>n-1-i) {
tmp=tmp/i;
}else {
tmp=tmp/(n-1-i);
}
if(tmp<min) {... | n | 558.java | 0.5 |
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner stdin = new Scanner(System.in);
/*int n = stdin.nextInt();
for(int i = 0; i < n; i++)
{
test(stdin);
}*/
test... | n | 559.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int n = in.nextInt();
int m = in.nextInt();
long boyMax = 0;
int NBoyMax = 0;
long sweets = ... | n | 563.java | 0.5 |
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
if(n==k){
String s=new String();
for(int i=0;i<k;i++){
s=s+"1";
}
System.ou... | n | 568.java | 0.5 |
//package com.krakn.CF.D1159;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, k;
n = sc.nextInt();
k = sc.nextInt();
int a = (n - k) / 2;
StringBuilder s = new StringBuilder();
... | n | 569.java | 0.5 |
class
MaximumSum
{
/*Function to return max sum such that no two elements
are adjacent */
int
FindMaxSum(
int
arr[],
int
n)
{
int
incl = arr[
0
];
int
excl =
0
;
int
excl_new;
int
i;
for
(i =
1
; i < n; i++)
{
/* current max excluding i */
excl_new = (incl > excl) ? incl : excl;
/* curren... | n | 57.java | 0.5 |
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
if(n==k){
String s=new String();
for(int i=0;i<k;i++){
s=s+"1";
}
System.ou... | n | 570.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SFly {
public static void main(String[] args) throws IOException {
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
int planet = Integer.parseInt(lector.readLine());
int ini... | n | 571.java | 0.5 |
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
/* spar5h */
public class cf1 implements Runnable{
public void run() {
InputReader s = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t = 1;
while(t-- > 0) {
int n = s.nextInt(), m ... | n | 574.java | 0.5 |
import java.util.*;
public class helloWorld
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
String str = in.next();
boolean[] exist = new boolean[200];
int dn[][] = new int[200][m+1];
for(int i = 0; i < n; i++) {
int ... | n | 578.java | 0.5 |
import java.io.*;
public class First {
StreamTokenizer in;
PrintWriter out;
int nextInt() throws IOException {
in.nextToken();
return (int)in.nval;
}
long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
String nextString() throws ... | n | 580.java | 0.5 |
import java.util.*;
import java.io.*;
public class Solution
{
public static void main(String [] args) throws IOException
{
PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenize... | n | 582.java | 0.5 |
import java.util.*;
public class helloWorld
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int cnt = 0;
String ans = "Yes";
for(int i = 0; i < n; i++)
cnt += in.nextInt();
for(int i = 0; i < n; i++)
cnt -= in.nextInt();
if(cnt < 0)
... | n | 588.java | 0.5 |
import java.util.*;
import java.io.*;
public class Piles {
static int summation(int arr[]) {
int k, sum=0;
for(k=0;k<arr.length;k++) {
sum = sum + arr[k];
}
return sum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n>=1 && n<=50) {
int ... | n | 589.java | 0.5 |
// JAVA Code to find total count of an element
// in a range
class
GFG {
// Returns count of element in arr[left-1..right-1]
public
static
int
findFrequency(
int
arr[],
int
n,
int
left,
int
right,
int
element)
{
int
count =
0
;
for
(
int
i = left -
1
; i < right; ++i)
if
(arr[i] == element)
+... | n | 59.java | 0.5 |
import java.util.Scanner;
public class Stones {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int s1=0;
int s2=0;
for (int i=0;i<n;++i)
s1+=input.nextInt();
for (int i=0;i<n;++i)
s2+=input.nextInt();
if (s1 >= s2)
System.out.println("Yes... | n | 590.java | 0.5 |
import java.util.Scanner;
public class Piles {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] a = new int[2]; int x = scan.nextInt();
for(int i = 0; i < 2; i++) for(int j = 0; j < x; j++) a[i] += scan.nextInt();
System.out.println(a[1] <= a[0] ? "Yes" : "No");
}
}
| n | 591.java | 0.5 |
import java.util.*;
import static java.lang.Math.*;
import java.io.*;
public class SolutionB {
public static void main(String args[])throws IOException{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
Set<Integer> se... | n | 593.java | 0.5 |
//package contese_476;
import java.util.*;
public class q1
{
int m=(int)1e9+7;
public class Node
{
int a;
int b;
public void Node(int a,int b)
{
this.a=a;
this.b=b;
}
}
public int mul(int a ,int b)
{
a=a%m;
b=b%m;
return((a*b)%m);
}
public int pow(int a,int b)
{
int x=1;
while(b>0)
{
if(b%2!=0)
x=mul... | n | 594.java | 0.5 |
/**
* Created by Baelish on 7/30/2018.
*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class B {
public static void main(String[] args)throws Exception {
FastReader in = new FastReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
int ans = -1... | n | 599.java | 0.5 |
// Java program to find max value of i*arr[i]
import
java.util.Arrays;
class
Test
{
static
int
arr[] =
new
int
[]{
10
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
// Returns max possible value of i*arr[i]
static
int
maxSum()
{
// Find array sum and i*arr[i] with no rotation
int
arrSum =
0
;
// ... | n | 6.java | 0.5 |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TaskA {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(S... | n | 603.java | 0.5 |
import java.util.*;
public class CoinsTask {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int S = in.nextInt();
int mCoins = 0;
while(S/n != 0) {
mCoins+=1;
S-=n;
}
mCoins = S == 0? mCoins : mCoins+1;
System.out.print(mCoins);
}
}
| n | 604.java | 0.5 |
import java.util.Scanner;
public class P1075A
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
long n,x,y;
n=scan.nextLong();
x=scan.nextLong();
y=scan.nextLong();
boolean flag=true,flag1=false,flag2=false;
long w1,w2,b1,b2;
long W=0l,B=0l;
w1=w2=1; b1=b2=n;
while(w... | n | 617.java | 0.5 |
import java.util.*;
public class kingrace {public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
long a = input.nextLong();
input.nextLine();
String [] coo = input.nextLine().split(" ");
long xcoin = Long.parseLong(coo[0]);
long ycoin = Long.parseLong(coo[1]);
coord... | n | 618.java | 0.5 |
// Java program to count the number of
// indexes in range L R such that
// Ai = Ai+1
class
GFG {
// function that answers every query
// in O(r-l)
static
int
answer_query(
int
a[],
int
n,
int
l,
int
r)
{
// traverse from l to r and count
// the required indexes
int
count =
0
;
for
(
int
i = ... | n | 62.java | 0.5 |
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt(),m=sc.nextInt();
int loca[]=new int[n+m];
int res[]=new int[m];
for(int i=0;i<n+m;i++)
loca[i]=sc.nextInt();
int y=0;
int driver[]=new int[m];
for(int i=0... | n | 621.java | 0.5 |
import java.util.Scanner;
public class TaxiDriversAndLyft2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long n = scanner.nextLong();
long m = scanner.nextLong();
long[] people = new long[(int) (n+m)];
int[] taxiDrivers = new int[(int) (n+m)];
for(int i = 0;i< ... | n | 622.java | 0.5 |
import java.util.*;
import java.io.*;
public class Solution{
public static long page(long p,long k){
return (p-1)/k;
}
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
i... | n | 632.java | 0.5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.