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 Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long s = sc.nextLong(); long ans = (s - 1) / n + 1; System.out.print(ans); } }
1
600.java
0.1
import java.util.*; public class OrangeJuice{ public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int s=in.nextInt(); if(n>=1&&n<=100000&&s>=1&&s<=1000000000){ if(s%n==0){ System.out.println(s/n); }else{ int o=s%n; System.out.println((s-o)/n+1); ...
1
601.java
0.1
import java.util.Scanner; /** * Solution */ public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), s = sc.nextInt(); int coins; if(s%n != 0) coins = s/n + 1; else coins = s/n; ...
1
602.java
0.1
import java .util.*; import java .io.*; public class Main{ public static void main(String[]YAHIA_MOSTAFA){ Scanner sc =new Scanner(System.in); long n=sc.nextLong(),x=sc.nextLong(),y=sc.nextLong(); long xb,xw,yb,yw; xw=x-1;yw=y-1;xb=n-x;yb=n-y; if (x==n&&y==n){ System.out.println("Black");return; } lon...
1
615.java
0.1
import java.util.*; import java.io.*; public class Param { public static void main( String[]args) { MyScanner param = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); long l2 =param.nextLong(); long dice1=param.nextLong(); l...
1
616.java
0.1
import java.io.BufferedReader; import java.io.InputStreamReader; public class Dont { static BufferedReader jin = new BufferedReader( new InputStreamReader( System.in ) ); static long n; static long x, y; public static void main(String[] args) throws Exception { n = nextLong(); x = next...
1
619.java
0.1
// Java program to count // the number of indexes // in range L R such that // Ai=Ai+1 class GFG { public static int N = 1000 ; // Array to store count // of index from 0 to // i that obey condition static int prefixans[] = new int [ 1000 ]; // precomputing prefixans[] array public static void countIn...
1
63.java
0.1
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int hp = scanner.nextInt(); if (hp%4 == 1){ System.out.println("0 A"); } else if (hp%4 == 2){ ...
1
643.java
0.1
//package Contest573; import java.io.*; import java.util.StringTokenizer; public class mainA { public static PrintWriter out = new PrintWriter(System.out); public static FastScanner enter = new FastScanner(System.in); public static void main(String[] args) throws IOException { int x=enter.nextIn...
1
644.java
0.1
import java.util.*; import java.io.*; public class TokitsukazeAndEnhancement { static char check(int n) { if(n%4 == 0) return 'D'; if(n%4 == 1) return 'A'; if(n%4 == 2) return 'C'; return 'B'; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(...
1
645.java
0.1
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class problem2 { static class tile implements Comparable<tile> { int number; int suit; public int compareTo(tile b){ return number - b.number; } } public static void main(St...
1
646.java
0.1
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static Scanner sc = new Scanner(System.in); public static char returnLetter(int n) { if(n%4==1) { return '...
1
647.java
0.1
//package codeforces; import java.util.Scanner; public class ex5 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String S [] = new String[3]; int m=0,s=0,p=0; int temp=0; for (int i = 0; i < S.length; i++) { S[i]=scan.next(); if(S[i].indexOf('m')!=-1) m++; if(S[i].indexO...
1
648.java
0.1
/* 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 { public static void main (String[] args) throws java.lang.Exception { // your code goes here long n,s,p; S...
1
718.java
0.1
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class AAA { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTok...
1
733.java
0.1
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.io.Input...
1
743.java
0.1
import java.util.*; public class helloWorld { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); long m = in.nextLong(); long ans = m / n; if(m % n > 0) ans++; System.out.println(ans); in.close(); } }
1
745.java
0.1
import com.sun.org.apache.xalan.internal.xslt.Process; import java.io.*; import java.util.*; public class main { public static void main(String[] args) throws IOException { init();//"prizes.in", "prizes.out"); int x = nextInt(); int y = nextInt(); int z = nextInt(); int t1 ...
1
757.java
0.1
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long s = sc.nextLong(); long ans = (s - 1) / n + 1; System.out.print(ans); } }
1
766.java
0.1
import java.io.*; import java.util.*; public class Codechef{ public static void main(String []args){ Scanner in = new Scanner(System.in); long n=in.nextLong(); long m=in.nextLong(); long k=in.nextLong(); long l=in.nextLong(); long j=((k+l)/m); if((k+l)%m!=0)j++; if((k+l>n) || j*m>n) { ...
1
775.java
0.1
import java.util.Scanner; public class origami { public static void main(String args[]){ Scanner input = new Scanner(System.in); double n = input.nextInt(); double k = input.nextInt(); double red = 0; double green = 0; double blue = 0; double ans = 0; red = (2 * n) / k; green = (5 * n) / k; blue ...
1
780.java
0.1
import java.util.Scanner; public class MargariteBestPresent_1080B { private static int f(int x) { return (x%2==0)?x/2:(x-1)/2-x; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n,r,l; n = sc.nextInt(); while(n-->0) { l = sc.nextInt(); r = sc.nextInt(); Syst...
1
781.java
0.1
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Map; import java.util.StringTokenizer; ...
1
782.java
0.1
import java.io.*; public class VJudgeProblem2{ public static void main(String[] args) throws IOException{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int x = Integer.parseInt(reader.readLine()); if (x == 1) System.out.println(-1); els...
1
791.java
0.1
import java.util.*; public class Main{ public static void main(String [] args) { Scanner scan=new Scanner(System.in); int q=scan.nextInt(); int i; for(i=1;i<=q;i++) { int a=scan.nextInt(); int ans=a/7+1; System.out.println(ans); ...
1
802.java
0.1
import java.util.Scanner; public class Main { static Scanner scan = new Scanner(System.in); public static void main(String [] args){ int num = scan.nextInt(); for(int i=0;i<num;i++){ int a = scan.nextInt(); int b = scan.nextInt(); System.out.println(a+" "+2...
1
804.java
0.1
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); if(a>=1 && a<=100){ if(a>2){ if(a%2==0){ System.out.println("YES"); }else{ System.out.println("NO"); } }else{ System.out.println("NO")...
1
813.java
0.1
import java.util.*; public class D5 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int a = input.nextInt(), v = input.nextInt(); int l = input.nextInt(), d = input.nextInt(), w = input.nextInt(); double lo = 0, hi = v; for(int iter = 0; iter < 1000; iter++) { ...
1
816.java
0.1
import java.io.*; import java.util.*; public class b { public static void main(String[] args) throws IOException, InterruptedException { Scanner zizo = new Scanner(System.in); PrintWriter wr = new PrintWriter(System.out); int n1 = 0,n2 = 0,n3 = 0,n4 = 0; int n = 3; while(n --> 0) { int x = zizo.nextI...
1
830.java
0.1
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 TrickyAlchemy { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public s...
1
832.java
0.1
import java.util.*; import java.math.*; public class Main{ public static void main(String [] args) { Scanner scan=new Scanner(System.in); long n=scan.nextLong(); long m=scan.nextLong(); n=(long)Math.pow(2,n); long ans=m%n; System.out.println(ans); } }
1
835.java
0.1
import java.util.*; import java.lang.Math; public class tab { public static void main(String[] args) { int n,pos,l,r; Scanner sc=new Scanner(System.in); n=sc.nextInt(); pos=sc.nextInt(); l=sc.nextInt(); r=sc.nextInt(); int sum; int a=(n-r)+(l-1); if((Math.abs(pos-l)<Math.abs(r-pos))&&a!=0) { if(l!=1) {sum=Math.abs(...
1
842.java
0.1
import java.util.Scanner; public class Main { //kai public static void main(String[] args) { Scanner kai = new Scanner(System.in); while (kai.hasNext()) { int a = kai.nextInt(); if ((a & 1) == 0) { System.out.println("Mahmoud"); }else { System.out.println("Ehab"); } } } } ...
1
858.java
0.1
import java.io.*; import java.util.*; public class cf { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()...
1
868.java
0.1
import java.io.*; import java.util.*; public class Codechef{ static int max=Integer.MIN_VALUE; static int res=0; static int[] checkMax(int arr[],int j){ int sum=0; int x=arr[j]; while(x!=0){ if(j+1==15){ j=0; }else{ ...
1
878.java
0.1
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 PizzaPizzaPizza { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public...
1
889.java
0.1
import java.util.*; import java.lang.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ FastReader sc=new FastReader(); ...
1
910.java
0.1
import java.util.*; public class helloWorld { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); int n = in.nextInt(); int ans = n - (a + b - c); if(ans < 1 || a >= n || b >= n || c > a || c > b) ans = ...
1
923.java
0.1
import java.util.*; public class Main { static int mod = 1000000007; static int size = 200000; static long[] fac = new long[size]; static long[] finv = new long[size]; static long[] inv = new long[size]; static int INF = Integer.MAX_VALUE; public static void main(String[] args){ Scanner scanner = new Scann...
1
925.java
0.1
import java.util.*; import java.io.*; import java.text.*; import java.math.*; import static java.lang.Integer.*; import static java.lang.Double.*; import java.lang.Math.*; public class two_squares { public static void main(String[] args) throws Exception { new two_squares().run(); } public void run() throws Exc...
1
931.java
0.1
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 AlexAndARhombus { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public...
1
995.java
0.1
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.L...
1
996.java
0.1
// A O(1) Java program to // find number of strings // that can be made under // given constraints. import java.io.*; class GFG { static int countStr( int n) { return 1 + (n * 2 ) + (n * ((n * n) - 1 ) / 2 ); } // Driver code public static void main (String[] args) { int n = 3 ; System.out...
1
262.java
0.1
// Java program to demonstrate working of // an algorithm that finds an element in an // array of infinite size class Test { // Simple binary search algorithm static int binarySearch( int arr[], int l, int r, int x) { if (r>=l) { int mid = l + (r - l)/ 2 ; if (arr[mid] == x) return mid; if (a...
logn
111.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn */ public class M...
logn
1157.java
0.3
import java.io.*; import java.util.StringTokenizer; import static java.lang.Math.max; import static java.lang.Math.min; public class Main { FastScanner in; PrintWriter out; void run() { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } ...
logn
1158.java
0.3
import java.util.*; public class ehab4 { public static void main( String[] args ) { Scanner in = new Scanner( System.in ); int a = 0, b = 0; System.out.println( "? 0 0 " ); System.out.flush(); int c = in.nextInt(); for ( int i = 29; i >= 0; i-- ) { System.out.println( "? " + ( a + ( 1 << i ) ) + ...
logn
1159.java
0.3
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import java.util.PriorityQueue; import static java.lang.Math.*; public class solution implements Runnable { static class InputReader { private In...
logn
1160.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn */ public class M...
logn
1161.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn */ public class M...
logn
1162.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
logn
1164.java
0.3
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class EhabAndAnotherAnotherXorProblem implements Closeable { private InputReader in = new InputRead...
logn
1165.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
logn
1166.java
0.3
import java.util.*; public class mad{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int cura = 0,curb = 0; int ver; System.out.println("? 0 0"); System.out.flush(); ver = sc.nextInt(); for(int i=29;i>=0;i--){ Sys...
logn
1168.java
0.3
import java.util.*; import java.lang.*; public class Main { static long m = 1000000007; static long powmod(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more // than or equal to p x = x % p; while (y > 0) { ...
logn
1169.java
0.3
/* package codechef; // 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 Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner in=new ...
logn
1170.java
0.3
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHe...
logn
1171.java
0.3
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 mid; /* If x is smaller than or equal to the first element, then return the first element */ if (x <= arr[low]) return low; /* If x is greater than the las...
logn
125.java
0.3
/* Program to check for majority element in a sorted array */ import java.io.*; class Majority { /* If x is present in arr[low...high] then returns the index of first occurrence of x, otherwise returns -1 */ static int _binarySearch( int arr[], int low, int high, int x) { if (high >= low) { int mid ...
logn
127.java
0.3
package com.rampatra.searching; /** * Created by IntelliJ IDEA. * * @author rampatra * @version 9/1/15 */ public class BinarySearch { /** * Searches an element {@param n} in a sorted array {@param a} * and returns its index in O(log n) time. The Index may not * correspond to the first occurren...
logn
1500.java
0.3
class findMedianTwoArrays { public static double main( int[] arr1, int start1, int end1, int[] arr2, int start2, int end2) { if ( end1 - start1 == 1 && end2 - start2 == 1 ) { return ( Math.max(arr1[start1], arr2[start2]) + Math.min(arr1[end1], arr2[end2]) ) / 2; } int median1Index = Math....
logn
1501.java
0.3
package com.interview.binarysearch; /** * There are two sorted arrays nums1 and nums2 of size m and n respectively. * Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). * * Solution * Take minimum size of two array. Possible number of partitions are from 0 to m in m ...
logn
1502.java
0.3
package com.interview.binarysearch; /** * http://www.geeksforgeeks.org/search-floor-and-ceil-in-a-sorted-array/ */ public class FloorAndCeilingSortedArray { public int floor(int input[], int x){ int low = 0; int high = input.length-1; while(low <= high){ int middle = (low + h...
logn
1503.java
0.3
package com.interview.algorithms.array; /** * Given a sorted array and a value x, the ceiling of x is the smallest element * in array greater than or equal to x, and the floor is the greatest element * smaller than or equal to x. Assume than the array is sorted in non-decreasing * order. Write efficient functions ...
logn
1504.java
0.3
package geek.livingstone.problems.arrays; /** * Full problem at * http://www.geeksforgeeks.org/search-floor-and-ceil-in-a-sorted-array/ * * @author emmanuel * */ public class FloorInSortedArray { public static int floor(int[] A, int val) throws Exception { if (val < A[0]) throw new Exception("All element...
logn
1505.java
0.3
package com.interview.binarysearch; /** * Regular binary search */ public class BinarySearch { public int search(final int input[], int search) { int low = 0; int high = input.length - 1; int mid; while (low <= high) { mid = low + ((high - low) / 2); if (i...
logn
1506.java
0.3
package com.interview.binarysearch; /** * http://www.careercup.com/question?id=4877486110277632 * Given a circle with N defined points and a point M outside the circle, * find the point that is closest to M among the set of N. O(LogN) * Test cases * 1) smallest element at center * 2) smallest element at left/ri...
logn
1507.java
0.3
package com.interview.binarysearch; /** * http://www.geeksforgeeks.org/find-the-point-where-a-function-becomes-negative/ */ public class MonotonicallyIncreasingFunctionBecomesPositive { private int f(int x){ return x*x - 10*x - 20; } public int findPoint(){ int i=1; while(f(...
logn
1508.java
0.3
package com.interview.binarysearch; /** * @author Tushar Roy * Date 01/22/17 * * Search in sorted and rotated array. In one version duplicate is not allowed and * in another version duplicate is allowed. * * Time complexity with no duplicate - O(logn) * Time complexity with duplicates - O(n) * * https://leet...
logn
1509.java
0.3
package com.interview.binarysearch; /** * Date 07/31/2016 * @author Tushar Roy * * Given a sorted array of integers, find the starting and ending position of a given target value. * * Time complexity O(logn) * Space complexity O(1) * * https://leetcode.com/problems/search-for-a-range/ */ public class Search...
logn
1510.java
0.3
package com.interview.binarysearch; /** * @author Tushar Roy * Date 01/17/2107 * A peak element is an element that is greater than its neighbors. Find index of peak element in the array. * * Space complexity is O(1) * Time complexity is O(n) * * https://leetcode.com/problems/find-peak-element/ */ public class...
logn
1511.java
0.3
package com.interview.binarysearch; /** * http://www.geeksforgeeks.org/check-for-majority-element-in-a-sorted-array/ */ public class FirstOccurrenceOfNumberInSortedArray { public int firstOccurrence(int input[], int x){ int low = 0; int high = input.length-1; while(low <= high){...
logn
1512.java
0.3
/** * Given a binary array sorted in non-increasing order, count the number of 1’s in it. **/ /* 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. */ class Ideone { public static int countOnes...
logn
1513.java
0.3
// http://www.geeksforgeeks.org/count-1s-sorted-binary-array/ class CountOne { public static void main(String[] args) { int[] arr={0, 0, 0, 0, 0, 0, 0}; //int[] arr={1, 1, 1, 1, 1, 1, 1}; //int[] arr = {1, 1, 1, 0, 0, 0, 0}; countOne(arr); } public static void countOne(int[] a) { int ...
logn
1514.java
0.3
public class Search { public static boolean find2(int[] array, int begin, int end, int element) { if (begin <= end) { int medium = begin + (end - begin) / 2; if (array[medium] == element) return true; else if (medium > begin && array[medium - 1] == elemen...
logn
1515.java
0.3
// Java program to reverse the number // using a stack import java.util.Stack; public class GFG { // Stack to maintain order of digits static Stack<Integer> st= new Stack<>(); // Function to push digits into stack static void push_digits( int number) { while (number != 0 ) { st.push(number % 1...
logn
218.java
0.3
// Java program to find number of // rotations in a sorted and rotated // array. import java.util.*; import java.lang.*; import java.io.*; class BinarySearch { // Returns count of rotations for an array // which is first sorted in ascending order, // then rotated static int countRotations( int arr[], ...
logn
22.java
0.3
// Java program to find minimum element in a sorted and rotated array import java.util.*; import java.lang.*; import java.io.*; class Minimum { static int findMin( int arr[], int low, int high) { // This condition is needed to handle the case when array // is not rotated at all if (high < low) retur...
logn
5.java
0.3
// Java implementation of recursive Binary Search class BinarySearch { // Returns index of x if it is present in arr[l.. // r], else return -1 int binarySearch( int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2 ; // If the element is present at the // middle itself if (a...
logn
512.java
0.3
// Java implementation of iterative Binary Search class BinarySearch { // Returns index of x if it is present in arr[], // else return -1 int binarySearch( int arr[], int x) { int l = 0 , r = arr.length - 1 ; while (l <= r) { int m = l + (r - l) / 2 ; // Check if x is present at mid if (arr[m] ...
logn
513.java
0.3
// Java program for Binary Search import java.util.*; class Binary { public static int f( int x) { return (x*x - 10 *x - 20 ); } // Returns the value x where above // function f() becomes positive // first time. public static int findFirstPositive() { // When first value itself is positive if...
logn
516.java
0.3
/* Java program to search an element in a sorted and pivoted array*/ class Main { /* Searches an element key in a pivoted sorted array arrp[] of size n */ static int pivotedBinarySearch( int arr[], int n, int key) { int pivot = findPivot(arr, 0 , n- 1 ); // If we didn't find a pivot, then // ar...
logn
519.java
0.3
// A Java program to divide and conquer based // efficient solution to find // median of two sorted arrays // of same size. import java.util.*; class GfG { /* This function returns median of ar1[] and ar2[]. Assumptions in this function: Both ar1[] and ar2[] are sorted arrays Both have n elements */ sta...
logn
521.java
0.3
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 mid; /* If x is smaller than or equal to the first element, then return the first element */ if (x <= arr[low]) return low; /* If x is greater than the las...
logn
527.java
0.3
// Java program to count // occurrences of an element class GFG { // A recursive binary search // function. It returns location // of x in given array arr[l..r] // is present, otherwise -1 static int binarySearch( int arr[], int l, int r, int x) { if (r < l) return - 1 ; int mid = l + (r - l...
logn
529.java
0.3
// Java program to check fixed point // in an array using binary search class Main { static int binarySearch( int arr[], int low, int high) { if (high >= low) { /* low + (high - low)/2; */ int mid = (low + high)/ 2 ; if (mid == arr[mid]) return mid; if (mid > arr[mid]) return binarySearch(arr,...
logn
534.java
0.3
// java program to find maximum // element class Main { // function to find the // maximum element static int findMaximum( int arr[], int low, int high) { /* Base Case: Only one element is present in arr[low..high]*/ if (low == high) return arr[low]; /* If there are two elements and first is...
logn
536.java
0.3
// A Java program to find a peak element element using divide and conquer import java.util.*; import java.lang.*; import java.io.*; class PeakElement { // A binary search based function that returns index of a peak // element static int findPeakUtil( int arr[], int low, int high, int n) { // Find in...
logn
538.java
0.3
// Java program to find minimum element in a sorted and rotated array import java.util.*; import java.lang.*; import java.io.*; class Minimum { static int findMin( int arr[], int low, int high) { // This condition is needed to handle the case when array // is not rotated at all if (high < low) retur...
logn
539.java
0.3
// Java program to find an element // in an almost sorted array class GFG { // A recursive binary search based function. // It returns index of x in given array // arr[l..r] is present, otherwise -1 int binarySearch( int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2 ; ...
logn
540.java
0.3
// Java program to count 1's in a sorted array class CountOnes { /* Returns counts of 1's in arr[low..high]. The array is assumed to be sorted in non-increasing order */ int countOnes( int arr[], int low, int high) { if (high >= low) { // get the middle index int mid = low + (high - low)/ 2 ; /...
logn
543.java
0.3
class SmallestMissing { int findFirstMissing( int array[], int start, int end) { if (start > end) return end + 1 ; if (start != array[start]) return start; int mid = (start + end) / 2 ; // Left half has all elements from 0 to mid if (array[mid] == mid) return findFirstMissing(array, mid+ 1 ...
logn
56.java
0.3
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; import java.util.stream.IntStream; public class B { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in ...
logn
715.java
0.3
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class OlyaAndMagicalSquare { void solve() { long[] dp = new long[32]; dp[0] = 0; for (int i = 1; i < 32...
logn
783.java
0.3
import java.util.*; public class ehab4 { public static void main( String[] args ) { Scanner in = new Scanner( System.in ); int a = 0, b = 0; System.out.println( "? 0 0 " ); System.out.flush(); int c = in.nextInt(); for ( int i = 29; i >= 0; i-- ) { System.out.println( "? " + ( a + ( 1 << i ) ) + ...
logn
794.java
0.3
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicReferenceArray; public class NastyaWardrobe { static long modulo = 1000000007; static long ans = 0; public static void main(String[] args) thro...
logn
927.java
0.3
// Java program to count occurrences // of an element class Main { /* if x is present in arr[] then returns the count of occurrences of x, otherwise returns -1. */ static int count( int arr[], int x, int n) { // index of first occurrence of x in arr[0..n-1] int i; // index of last occurrence of x...
logn
530.java
0.3
import java.util.*; import java.io.*; public class code{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int ok,ok2; int va,vb; va = 0; vb = 0; out.println("? "+va+"...
logn
1167.java
0.3
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class A1180 { public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(System.in); int n ...
n
1000.java
0.5
import java.util.*; import java.io.*; import java.math.*; public class round569d2b { public static void main(String args[]) { FastScanner in = new FastScanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } if (n % 2 == 0) { for (i...
n
1002.java
0.5