content stringlengths 219 31.2k | complexity stringclasses 5
values | file_name stringlengths 6 9 | complexity_ranked float64 0.1 0.9 |
|---|---|---|---|
import java.util.*;
public class java{
public static void main(String[]arg) {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
String s=sc.next();
boolean f=true;
boolean f2=true;
boolean f3=true;
boolean f4=true;
int v=0;
... | n | 848.java | 0.5 |
// A O(n) and O(n) extra space Java program to find
// longest common subarray of two binary arrays with
// same sum
class
Test
{
static
int
arr1[] =
new
int
[]{
0
,
1
,
0
,
1
,
1
,
1
,
1
};
static
int
arr2[] =
new
int
[]{
1
,
1
,
1
,
1
,
1
,
0
,
1
};
// Returns length of the longest common s... | n | 85.java | 0.5 |
import java.util.*;
import java.io.*;
public class Waw{
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] a = new long[n];
for(int i=0;i<n;i++) a[i] = sc.nextLong();
long[] p = new long[n];
... | n | 851.java | 0.5 |
import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, f[], c=0;
n = in.nextInt();
f = new int[n];
while (--n>0){
f[in.nextInt()-1] ++;
f[in.nextInt()-1]++;
in.nextLine();
}
for(int i=0; i<f.length; i++) if (f[i] =... | n | 854.java | 0.5 |
/*
* Created on 17.05.2019
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author Wolfgang Weck
*/
public class C01Easy {
public static void main(String[] args) {
try (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {
final Strin... | n | 856.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Code {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Ha... | n | 857.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
private static void solve(InputReader in, OutputWriter out) {
int n = in.nextInt();
if (n < 6) {
out.println(-1);
} else {
int m = (n - 2);
for (int i = 2; i <= m; i++) {
out.prin... | n | 860.java | 0.5 |
import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
static class InputReader {
public BufferedReader br;
public StringTokenizer token;
public InputReader(InputStream stream)
{
br=new BufferedReader(new InputStreamReader(stream),32768);
... | n | 861.java | 0.5 |
import java.io.*;
import java.util.*;
public class LectureSleep {
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = nu... | n | 864.java | 0.5 |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Equator {
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static ... | n | 867.java | 0.5 |
import java.io.*;
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int ans = 0;
int t= sc.nextInt();
int arr[] = new int[... | n | 869.java | 0.5 |
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.math.*;
public class C {
public static void main(String[] args) throws IOException {
/**/
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
/*/
Scanner sc = new Scanner(new BufferedReader(new I... | n | 874.java | 0.5 |
import java.util.*;
public class Main{
private static final int MAX_SIZE = 100005;
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(((m + 1) / ... | n | 875.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
public void solve() {
int n = ni();
int a = ni();
int b = ni();
long ans = 0;
HashMap<Long, Long> m = new HashMap<>();
HashMap<String, Long> s = new HashMap<>();
for (int i = 0; i < n; i++) {
... | n | 880.java | 0.5 |
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Practice {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String s... | n | 881.java | 0.5 |
import java.util.*;
import java.io.*;
public class TwoGram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
HashMap <String, Integer> hm = new HashMap<>();
for (int i = 0; i < n - 1; i++) {
... | n | 883.java | 0.5 |
import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bf.readLine());
int[]f=new int[1001... | n | 886.java | 0.5 |
import java.io.*;
import java.util.Scanner;
public class abc{
public static int check(StringBuilder s)
{
int countRemove=0;
if(!s.toString().contains("xxx")) return countRemove;
else{
for(int i=1;i<s.length()-1;i++)
{
if(s.charAt(i-1)=='x' && s.charAt(i)=='x' && s.charA... | n | 887.java | 0.5 |
class
MergeArrays
{
/* Function to move m elements at the end of array mPlusN[] */
void
moveToEnd(
int
mPlusN[],
int
size)
{
int
i, j = size -
1
;
for
(i = size -
1
; i >=
0
; i--)
{
if
(mPlusN[i] != -
1
)
{
mPlusN[j] = mPlusN[i];
j--;
}
}
}
/* Merges array N[] of size n into array mPl... | n | 89.java | 0.5 |
import java.util.Scanner;
public class TreasureHunt {
public static String Solve() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String kuro = sc.nextLine(), shiro = sc.nextLine(), katie = sc.nextLine();
sc.close();
String[] output = {"Kuro", "Shiro", "Katie", "Draw"};
if... | n | 890.java | 0.5 |
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Practice {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int n=0;
in... | n | 892.java | 0.5 |
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner (System.in);
public static void main(String[] args) {
int n = sc.nextInt();
int k = sc.nextInt();
char str[][] = new char[5][n];
for(int i = 0;i < 4;i ++){
for(int j = 0;j <... | n | 893.java | 0.5 |
import java.util.*;
public class A
{
public static int palin(String str)
{
int flag=0;
int l=str.length();
for(int i=0;i<l/2;i++)
{
if(str.charAt(i)!=str.charAt(l-i-1))
{
flag=1;
break;
}
}
if(fla... | n | 896.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
private static void solve(InputReader in, OutputWriter out) {
int n = in.nextInt();
List<List<Integer>> g = new ArrayList<>(n + 1);
for (int i = 0; i < n + 1; i++) {
g.add(new LinkedList<>());
}
int deg... | n | 898.java | 0.5 |
// Java program to Split the array and
// add the first part to the end
class
Geeks
{
/* Function to reverse arr[] from index start to end*/
static
void
rvereseArray(
int
arr[],
int
start,
int
end)
{
while
(start < end) {
int
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--... | n | 9.java | 0.5 |
// Efficient Java program to sort an
// array of numbers in range from 1
// to n.
import
java.io.*;
import
java.util.*;
public
class
GFG {
// function for sort array
static
void
sortit(
int
[]arr,
int
n)
{
for
(
int
i =
0
; i < n; i++)
{
arr[i]=i+
1
;
}
}
// Driver code
public
static
v... | n | 90.java | 0.5 |
import java.util.*;
public class mohamedy23
{
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();String s=sc.next();int i=s.length()-1;
if(n==1) {
if(s.charAt(0)=='1') {
System.out.print("YES");return;
}e... | n | 900.java | 0.5 |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Arr... | n | 902.java | 0.5 |
import
java.util.Arrays;
// Java program to test whether an array
// can be sorted by swapping adjacent
// elements using boolean array
class
GFG {
// Return true if array can be
// sorted otherwise false
static
boolean
sortedAfterSwap(
int
A[],
boolean
B[],
int
n)
{
int
i, j;
// Check bool arra... | n | 91.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
static StringBuilder data = new StringBuilder();
final static FastReader in = new FastReader();
public static void main(String[] args) {
int n = in.nextInt(), k = in.nextInt(), t;
int[] a = new int[101];
int answ = 0;
... | n | 913.java | 0.5 |
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
IO io = new IO();
String s=io.nextLine();
if (s.length()<3)io.println("No");
else {
int[]b=new int[200];
for (int i=2;i<s.length();i++){
b... | n | 916.java | 0.5 |
import javax.print.DocFlavor;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.CookieHandler;
import java.nio.Buffer;
import java.nio.charset.IllegalCharsetNameException;
import java.sql.BatchUpdateException;
import... | n | 917.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author Haya
*/
public class CommentaryBoxes {
public static void main(String[] args) {
FastReader in = new FastReader();
long n = in.nextLo... | n | 918.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
public class Main {
private FastScanner scanner = new FastScanner();
public static void main(String[] args) {
new Main().solve();
}
private void ... | n | 921.java | 0.5 |
import java.util.HashSet;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashSet<Integer> set = new HashSet<>();
for(int i = 0; i<n; i++){
int a = sc.nextInt();
... | n | 926.java | 0.5 |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Fingerprints {
public static BufferedReader in = new BufferedRead... | n | 929.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine... | n | 935.java | 0.5 |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
System.out.println(solve(a));
sc.close();
}
... | n | 938.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
static StringBuilder data = new StringBuilder();
final static FastReader in = new FastReader();
public static void main(String[] args) {
int n = in.nextInt(), m = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n;... | n | 939.java | 0.5 |
import java.util.*;
public class Solution{
public static void main(String sp[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
String st = sc.next();
char arr[] = st.toCharArray();
boolean b=false;
for(char j='a';j<='z';j++){
for(int i=0;i<arr.length;i++){
if... | n | 940.java | 0.5 |
import java.io.*;
import java.util.*;
public class D999 {
public static void main(String args[])throws IOException
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int req=n/m;
int arr[]=new int[n+1];
int size[]=new int[m];
Lis... | n | 941.java | 0.5 |
import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
static class InputReader {
public BufferedReader br;
public StringTokenizer token;
public InputReader(InputStream stream)
{
br=new BufferedReader(new InputStreamReader(stream),32768);
... | n | 942.java | 0.5 |
import java.util.*;
import java.io.*;
public class A
{
public static void main(String ar[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1[]=br.readLine().split(" ");
String s2[]=br.readLine().split(" ");
i... | n | 944.java | 0.5 |
import java.io.PrintWriter;
import java.util.Scanner;
public class pr902A {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int m = in.nextInt();
out.println(solve(n, m));... | n | 946.java | 0.5 |
import java.util.*;
public class ErrorCorrectSystem
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String a = scan.next();
String b = scan.next();
int[][] mismatch = new int[26][26];
for(int i = 0; i < 26; i++) Arrays.fill(mismatch[i], -1);
... | n | 947.java | 0.5 |
import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;
// _ h _ r _ t r _
// _ t _ t _ s t _
public class TaskA implements Runnable {
long m = (int)1e9+7;
PrintWriter w;
InputReader c;
final int MAXN = (int)1e6 + 100;
public void run() {
c = new Input... | n | 948.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
public class Solution1 implements Runnable
{
static final lo... | n | 951.java | 0.5 |
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.HashMap;
public class Main
{
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
... | n | 952.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.
*/
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Ahmed
*/
public class Watermelon {
static class Pas... | n | 963.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 s = sc.nextInt();
int[] f = new int[n];
int[] t = new int[n];
for (int i = 0; i < n; i++) {
f[i] = sc.nextInt();
t[i] = sc.nextInt();
}
System.ou... | n | 965.java | 0.5 |
import java.util.Scanner;
/**
*
* @author User
*/
public class Code {
static int [] reverse(int a[])
{
int[] b = new int[a.length];
int j = 0 ;
for (int i = a.length-1; i >= 0; i--) {
b[i] = a[j] ;
j++;
}
return b ;
}
public static ... | n | 968.java | 0.5 |
import java.util.Scanner;
public class HammingDistancesSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine(), b = sc.nextLine();
long sum = 0;
int frequency[][] = new int[200010][2];
for (int i = 1; i <= b.length(); i++) {
for (int j = 0; j < ... | n | 969.java | 0.5 |
// Java program to find union of
// two sorted arrays
class
FindUnion
{
/* Function prints union of arr1[] and arr2[]
m is the number of elements in arr1[]
n is the number of elements in arr2[] */
static
int
printUnion(
int
arr1[],
int
arr2[],
int
m,
int
n)
{
int
i =
0
, j =
0
;
while
(i < m && j... | n | 97.java | 0.5 |
import java.io.*;
import java.lang.*;
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main {
Main() throws IOException {
... | n | 970.java | 0.5 |
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] x = new int [200010][10];
String a = sc.nextLine();
String b = sc.nextLine();
int n = a.length();
int m = b.length();
for (int i = 1; i <= m; i++) {
... | n | 971.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
public class Main2 {
private FastScanner scanner = new FastScanner();
public static void main(String[] args) {
new Main2().solve();
}
private void... | n | 972.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 Ideone
{
static int check(int temp)
{
int count1 = 0;
while (temp>0)
{
if(temp % 2 != 0)
cou... | n | 973.java | 0.5 |
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class TaskB implements Runnable {
boolean prime[] = new boolean[(int)1e6+10];
InputReader c;
PrintWriter w;
public void run() {
c = new InputRea... | n | 974.java | 0.5 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class BOOL {
static char [][]ch;
static int n,m;
private static FastReader in =new FastReader();
public static void main(String[] args) {
int n=in.nextInt();
int a[]=new int[100000... | n | 976.java | 0.5 |
import java.util.Scanner;
public class codef8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int beacon[] = new int[1000001];
for (int i = 0; i < num; i++) {
beacon[sc.nextInt()] = sc.nextInt();
}
int dp[] =... | n | 977.java | 0.5 |
import java.util.Scanner;
public class codef8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int beacon[] = new int[1000001];
int pos[] = new int[num];
for (int i = 0; i < num; i++) {
int position = sc.nextInt... | n | 978.java | 0.5 |
import java.util.Scanner;
public class codef8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int beacon[] = new int[1000001];
int pos[] = new int[num];
for (int i = 0; i < num; i++) {
int position = sc.nextInt... | n | 979.java | 0.5 |
// Java program to find union of two
// sorted arrays (Handling Duplicates)
class
FindUnion
{
static
void
UnionArray(
int
arr1[],
int
arr2[])
{
// Taking max element present in either array
int
m = arr1[arr1.length -
1
];
int
n = arr2[arr2.length -
1
];
int
ans =
0
;
if
(m > n)
{
ans = m; ... | n | 98.java | 0.5 |
import java.util.Scanner;
public class ChainReaction {
public static void main(String [] args) {
Scanner kb = new Scanner(System.in);
int num = kb.nextInt();
int[] beacons = new int[1000002];
for (int i=0; i<num; i++) {
beacons[kb.nextInt()] = kb.nextInt();
}
int [] dp = new int[1000002];
int... | n | 981.java | 0.5 |
import java.util.*;
import java.io.*;
import java.math.*;
public class round569d2a {
public static void main(String args[]) {
FastScanner in = new FastScanner(System.in);
int n = in.nextInt();
int sum = 1;
int tracker = 4;
while (n > 1) {
sum += tracker;
tracker += 4;
n--;
}
System.out.println... | n | 994.java | 0.5 |
import java.io.*;
import java.util.*;
public class Main {
static InputReader in = new InputReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
static long oo = 1000000000000L;
static int[][] memo;
public static void main(String[] args) throws IOException {
int[] cnt = new int[10... | n | 997.java | 0.5 |
import java.io.*;
import java.lang.*;
import java.util.*;
public class alex
{
public static void main(String[] args)throws IOException
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int sum=1;
for(int i=1;i<=n;i++)
{
sum=sum+(4*(i-1));
}
Syste... | n | 998.java | 0.5 |
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int num=1;
int add;
for(int i=1;i<n;i++){
add=4*i;
num+=add;
}
System.out.println(num);
}
} | n | 999.java | 0.5 |
// Java program to find the only repeating
// element in an array where elements are
// from 1 to n-1.
class
GFG
{
static
int
findRepeating(
int
arr[],
int
n)
{
// res is going to store value of
// 1 ^ 2 ^ 3 .. ^ (n-1) ^ arr[0] ^
// arr[1] ^ .... arr[n-1]
int
res =
0
;
for
(
int
i =
0
; i < n - ... | n | 114.java | 0.5 |
import
java.util.HashMap;
/* Program for finding out majority element in an array */
class
MajorityElement
{
private
static
void
findMajority(
int
[] arr)
{
HashMap<Integer,Integer> map =
new
HashMap<Integer, Integer>();
for
(
int
i =
0
; i < arr.length; i++) {
if
(map.containsKey(arr[i])) {
int
cou... | n | 130.java | 0.5 |
// Java code to find maximum triplet sum
import
java.io.*;
import
java.util.*;
class
GFG {
// This function assumes that there
// are at least three elements in arr[].
static
int
maxTripletSum(
int
arr[],
int
n)
{
// Initialize Maximum, second maximum and third
// maximum element
int
maxA = -
1000... | n | 137.java | 0.5 |
/* Java program to check if linked list is palindrome recursively */
class
LinkedList {
Node head;
// head of list
Node left;
/* Linked list Node*/
class
Node {
char
data;
Node next;
Node(
char
d)
{
data = d;
next =
null
;
}
}
// Initial parameters to this function are &head and head
b... | n | 160.java | 0.5 |
// Java program to find maximum sum
// of all rotation of i*arr[i] using pivot.
import
java.util.*;
import
java.lang.*;
import
java.io.*;
class
GFG
{
// function definition
static
int
maxSum(
int
arr[],
int
n)
{
int
sum =
0
;
int
i;
int
pivot = findPivot(arr, n);
// difference in pivot and index... | n | 20.java | 0.5 |
// Most efficient Java program to count all
// substrings with same first and last characters.
public
class
GFG {
// assuming lower case only
static
final
int
MAX_CHAR =
26
;
static
int
countSubstringWithEqualEnds(String s)
{
int
result =
0
;
int
n = s.length();
// Calculating frequency of each ch... | n | 259.java | 0.5 |
// Java program for nth Catalan Number
class
GFG {
// Returns value of Binomial Coefficient C(n, k)
static
long
binomialCoeff(
int
n,
int
k) {
long
res =
1
;
// Since C(n, k) = C(n, n-k)
if
(k > n - k) {
k = n - k;
}
// Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
for
(
int
i =
0... | n | 291.java | 0.5 |
// A O(n) time and O(1) extra
// space solution to calculate
// the Permutation Coefficient
import
java.io.*;
class
GFG
{
static
int
PermutationCoeff(
int
n,
int
k)
{
int
Fn =
1
, Fk =
1
;
// Compute n! and (n-k)!
for
(
int
i =
1
; i <= n; i++)
{
Fn *= i;
if
(i == n - k)
Fk = Fn;
}
in... | n | 297.java | 0.5 |
class
GFG {
// Returns count of ways n people
// can remain single or paired up.
static
int
countFriendsPairings(
int
n)
{
int
a =
1
, b =
2
, c =
0
;
if
(n <=
2
) {
return
n;
}
for
(
int
i =
3
; i <= n; i++) {
c = b + (i -
1
) * a;
a = b;
b = c;
}
return
c;
}
// Driver code
pu... | n | 301.java | 0.5 |
// Java program to find remaining
// chocolates after k iterations
class
GFG
{
// A O(n) C++ program to count
// even length binary sequences
// such that the sum of first
// and second half bits is same
// Returns the count of
// even length sequences
static
int
countSeq(
int
n)
{
int
nCr =
1
, res =
... | n | 312.java | 0.5 |
// A simple JAVA program to rearrange
// contents of arr[] such that arr[j]
// becomes j if arr[i] is j
class
GFG {
// A simple method to rearrange
// 'arr[0..n-1]' so that 'arr[j]'
// becomes 'i' if 'arr[i]' is 'j'
static
void
rearrange(
int
arr[],
int
n)
{
for
(
int
i =
0
; i < n; i++) {
// ret... | n | 34.java | 0.5 |
// Java program to find all elements
// in array which have atleast
// two greater elements itself.
import
java.util.*;
import
java.io.*;
class
GFG
{
static
void
findElements(
int
arr[],
int
n)
{
int
first = Integer.MIN_VALUE;
int
second = Integer.MAX_VALUE;
for
(
int
i =
0
; i < n; i++)
{
// If... | n | 49.java | 0.5 |
// Java O(n) solution for
// finding smallest subarray
// with sum greater than x
import
java.io.*;
class
GFG
{
// Returns length of smallest
// subarray with sum greater
// than x. If there is no
// subarray with given sum,
// then returns n+1
static
int
smallestSubWithSum(
int
arr[],
int
n,
int
x)
{... | n | 77.java | 0.5 |
// Java program to find intersection of
// two sorted arrays
class
FindIntersection
{
/* Function prints Intersection of arr1[] and arr2[]
m is the number of elements in arr1[]
n is the number of elements in arr2[] */
static
void
printIntersection(
int
arr1[],
int
arr2[],
int
m,
int
n)
{
int
i =
0
,... | n | 99.java | 0.5 |
// Java program to rotate an array by
// d elements
class
RotateArray {
/*Function to left rotate arr[] of size n by d*/
void
leftRotate(
int
arr[],
int
d,
int
n)
{
for
(
int
i =
0
; i < d; i++)
leftRotatebyOne(arr, n);
}
void
leftRotatebyOne(
int
arr[],
int
n)
{
int
i, temp;
temp = arr[
0
]... | n_square | 1.java | 0.9 |
import java.io.*;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class D {
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new O... | n_square | 1014.java | 0.9 |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
public class D {
int[][] fast(int n, int m){
int[][] ans = new int[2][n * m];
int c = 0;
for (int left = 1, ri... | n_square | 1015.java | 0.9 |
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.*;
public class E1180D {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.nextInt();
in... | n_square | 1016.java | 0.9 |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D {
private void solve() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt(), m = nextI... | n_square | 1017.java | 0.9 |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D {
private void solve() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt(), m = nextI... | n_square | 1018.java | 0.9 |
// Java program to count number of triangles that can be
// formed from given array
import
java.io.*;
import
java.util.*;
class
CountTriangles
{
// Function to count all possible triangles with arr[]
// elements
static
int
findNumberOfTriangles(
int
arr[])
{
int
n = arr.length;
// Sort the array elem... | n_square | 102.java | 0.9 |
import java.util.*;
public class TestClass
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
int arr[] = new int[n+1];
for(int i =0;i<n;i++)
arr[i+1]= in.nextInt();
long sum[] = ne... | n_square | 1035.java | 0.9 |
import java.util.*;
import java.math.*;
public class Solution{
private long [] sums;
private void solve(){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int [] arr = new int[n];
this.sums = new long[n];
... | n_square | 1036.java | 0.9 |
//package ContestEd69;
import java.io.*;
import java.util.StringTokenizer;
public class mainD {
public static PrintWriter out = new PrintWriter(System.out);
public static FastScanner enter = new FastScanner(System.in);
public static long[] arr;
public static void main(String[] args) throws IOException... | n_square | 1037.java | 0.9 |
import java.util.*;
import javax.lang.model.util.ElementScanner6;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
Prin... | n_square | 1038.java | 0.9 |
// A simple Java program to
//count pairs with difference k
import
java.util.*;
import
java.io.*;
class
GFG {
static
int
countPairsWithDiffK(
int
arr[],
int
n,
int
k)
{
int
count =
0
;
// Pick all elements one by one
for
(
int
i =
0
; i < n; i++)
{
// See if there is a pair
// of this picke... | n_square | 104.java | 0.9 |
// Java program program to merge two
// sorted arrays with O(1) extra space.
import
java.util.Arrays;
class
Test
{
static
int
arr1[] =
new
int
[]{
1
,
5
,
9
,
10
,
15
,
20
};
static
int
arr2[] =
new
int
[]{
2
,
3
,
8
,
13
};
static
void
merge(
int
m,
int
n)
{
// Iterate through all elements... | n_square | 107.java | 0.9 |
// Java Program to find max subarray
// sum excluding some elements
import
java.io.*;
class
GFG {
// Function to check the element
// present in array B
static
boolean
isPresent(
int
B[],
int
m,
int
x)
{
for
(
int
i =
0
; i < m; i++)
if
(B[i] == x)
return
true
;
return
false
;
}
// Util... | n_square | 115.java | 0.9 |
// java program to find maximum
// equilibrium sum.
import
java.io.*;
class
GFG {
// Function to find maximum
// equilibrium sum.
static
int
findMaxSum(
int
[]arr,
int
n)
{
int
res = Integer.MIN_VALUE;
for
(
int
i =
0
; i < n; i++)
{
int
prefix_sum = arr[i];
for
(
int
j =
0
; j < i; j++)
... | n_square | 117.java | 0.9 |
// Java program to find equilibrium
// index of an array
class
EquilibriumIndex {
int
equilibrium(
int
arr[],
int
n)
{
int
i, j;
int
leftsum, rightsum;
/* Check for indexes one by one until
an equilibrium index is found */
for
(i =
0
; i < n; ++i) {
/* get left sum */
leftsum =
0
;
for
(j =
... | n_square | 120.java | 0.9 |
class
LeadersInArray
{
/*Java Function to print leaders in an array */
void
printLeaders(
int
arr[],
int
size)
{
for
(
int
i =
0
; i < size; i++)
{
int
j;
for
(j = i +
1
; j < size; j++)
{
if
(arr[i] <= arr[j])
break
;
}
if
(j == size)
// the loop didn't break
System.out.print(arr[i] +
"... | n_square | 122.java | 0.9 |
// Java program to find Majority
// element in an array
import
java.io.*;
class
GFG {
// Function to find Majority element
// in an array
static
void
findMajority(
int
arr[],
int
n)
{
int
maxCount =
0
;
int
index = -
1
;
// sentinels
for
(
int
i =
0
; i < n; i++)
{
int
count =
0
;
for
(
int
... | n_square | 128.java | 0.9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.