├── BirthdayCakeCandles └── BirthdayCakeCandles.java ├── Booking ├── 1 Booking B.Hacking - the challenge starts here! __ powered by HackerRank.pdf ├── 2 Booking B.Hacking - the challenge starts here! __ powered by HackerRank.pdf ├── 3 Booking B.Hacking - the challenge starts here! __ powered by HackerRank.pdf ├── 4 Booking B.Hacking - the challenge starts here! __ powered by HackerRank.pdf ├── Booking4.java ├── CountPolygons.java ├── DeltaEncoding.java └── SortHotelsList.java ├── CheckValueInArray ├── ReadME.md └── myCode.java ├── CompareTheTriplets └── CompareTheTriplets.java ├── ConnectingTowns ├── ConnectingTowns.Java └── ReadME.md ├── CuttingPaperSquares ├── CuttingPaperSquares.Java └── ReadME.md ├── DiagonalDifference └── DiagonalDifference.java ├── FizzBuzz ├── ReadME.md └── myCode.java ├── Handshake ├── Handshake.Java └── ReadME.md ├── Hourglass2DArrays └── Hourglass2DArrays.java ├── Iteration number-word ├── ReadME.md └── myCode.java ├── MergeCharString └── MergeCharString.java ├── MiniMaxSum └── MiniMaxSum.java ├── OddEvenString └── StringOddEven.java ├── OddNumberInARange └── OddNumber.java ├── README.md ├── ReverseWord ├── ReadME.md └── myCode.Java ├── Staircase └── Staircase.java ├── StrangeGridAgain ├── ReadME.md └── Solution.java ├── StringAscendingOrder ├── ReadME.md └── myCode.java ├── StringCompare └── StringCompare.java └── TimeConversion └── TimeConversion.java /BirthdayCakeCandles/BirthdayCakeCandles.java: -------------------------------------------------------------------------------- 1 | package BirthdayCakeCandles; 2 | import java.io.*; 3 | import java.util.*; 4 | import java.text.*; 5 | import java.math.*; 6 | import java.util.regex.*; 7 | public class BirthdayCakeCandles { 8 | 9 | static int birthdayCakeCandles(int n, int[] ar) { 10 | // Complete this function 11 | int max=ar[0],count=1; 12 | for(int ar_i = 1; ar_i < n; ar_i++){ 13 | if(max=arr_calls[j].getStart() && 51 | arr_calls[i].getEnd()="+arr_calls[j].getStart()+ 54 | "&&"+arr_calls[i].getEnd()+"<"+arr_calls[j].getEnd());*/ 55 | sovr++;} 56 | }} 57 | 58 | } 59 | System.out.println( ((sovr-x_customer)==0 ? 0: sovr-x_customer)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Booking/CountPolygons.java: -------------------------------------------------------------------------------- 1 | package Booking; 2 | import java.io.*; 3 | import java.util.*; 4 | import java.text.*; 5 | import java.math.*; 6 | import java.util.regex.*; 7 | 8 | public class CountPolygons { 9 | 10 | public static class Polygons{ 11 | int a,b,c,d; 12 | int countSquare,countRect,countOthers; 13 | 14 | public Polygons() { 15 | countSquare=0; 16 | countRect=0; 17 | countOthers=0; 18 | } 19 | 20 | public void addNewPolygon(int a, int b, int c, int d) { 21 | // TODO Auto-generated method stub 22 | if (a <= 0 || b <= 0 || c <= 0 | d <= 0) { 23 | this.countOthers++; 24 | return; 25 | } 26 | 27 | if (a == c && b == d) { 28 | if (a == b) { 29 | this.countSquare++; 30 | } else { 31 | this.countRect++; 32 | } 33 | } else { 34 | this.countOthers++; 35 | } 36 | } 37 | 38 | public int getCountSquare() { 39 | return countSquare; 40 | } 41 | 42 | public int getCountRect() { 43 | return countRect; 44 | } 45 | 46 | public int getCountOthers() { 47 | return countOthers; 48 | } 49 | 50 | 51 | } 52 | 53 | 54 | public static void main(String[] args) { 55 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ 56 | 57 | Scanner in = new Scanner(System.in); 58 | Polygons p = new Polygons();; 59 | 60 | while (in.hasNextInt()) { 61 | int a = in.nextInt(); 62 | int b = in.nextInt(); 63 | int c = in.nextInt(); 64 | int d = in.nextInt(); 65 | 66 | p.addNewPolygon(a,b,c,d); 67 | } 68 | System.out.println(p.getCountSquare() + " " + 69 | p.getCountRect() + " " + 70 | p.getCountOthers()); 71 | } 72 | } -------------------------------------------------------------------------------- /Booking/DeltaEncoding.java: -------------------------------------------------------------------------------- 1 | package Booking; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class DeltaEncoding { 8 | 9 | public static void main(String[] args) { 10 | //Data una lista di numeri. 11 | //25626 25757 24367 24267 16 100 2 7277 12 | int[] numeri; 13 | /*Output 14 | Output a delta encoding for the sequence. In a delta encoding, the first element is 15 | reproduced as-is. Each subsequent element is represented as the numeric difference 16 | from the element before it. E.g. for the sequence above, the delta encoding would be: 17 | 25626 131 -1390 -100 -24251 84 -98 7275*/ 18 | //=> 25626 -128 131 -128 -1390 -100 -128 -24251 84 -98 -128 7275 19 | 20 | Scanner in = new Scanner(System.in);//.toLowerCase() 21 | /*while ( in.hasNextInt() ) { 22 | numero = in.nextInt(); 23 | }*/ 24 | String str= in.nextLine(); 25 | String[] numbers=str.split(" "); 26 | 27 | int[] deltaArray=new int[numbers.length]; 28 | int i=0;deltaArray[0]=Integer.parseInt(numbers[0]); 29 | 30 | //System.err.println(numbers.length); 31 | for(i=1;i128) 41 | System.out.print("-128 "+deltaArray[i]+" "); 42 | else System.out.print(deltaArray[i]+" "); 43 | 44 | } 45 | 46 | in.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Booking/SortHotelsList.java: -------------------------------------------------------------------------------- 1 | package Booking; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class SortHotelsList { 8 | 9 | public static void main(String[] args) { 10 | Map list=new HashMap(); 11 | Scanner in = new Scanner(System.in);//.toLowerCase() 12 | String key_words=in.nextLine(); 13 | String[] key_word=key_words.split("\\s+"); 14 | int M = in.nextInt();in.nextLine(); //which is the number of reviews 15 | String[] reviews=new String[2*M]; 16 | int count; 17 | for(int i=0;i20000) && (M<0 && M>15000)); 17 | 18 | String nlines = br.readLine(); 19 | String[] nValues=new String[N]; 20 | for(int i=0;ib[i]) 20 | res[0]++; 21 | else 22 | res[1]++; 23 | } 24 | } 25 | 26 | return res; 27 | } 28 | 29 | public static void main(String[] args) { 30 | Scanner in = new Scanner(System.in); 31 | int a0 = in.nextInt(); 32 | int a1 = in.nextInt(); 33 | int a2 = in.nextInt(); 34 | int b0 = in.nextInt(); 35 | int b1 = in.nextInt(); 36 | int b2 = in.nextInt(); 37 | int[] result = solve(a0, a1, a2, b0, b1, b2); 38 | for (int i = 0; i < result.length; i++) { 39 | System.out.print(result[i] + (i != result.length - 1 ? " " : "")); 40 | } 41 | System.out.println(""); 42 | 43 | 44 | } 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ConnectingTowns/ConnectingTowns.Java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.text.*; 4 | import java.util.*; 5 | import java.util.regex.*; 6 | 7 | public class ConnectingTowns { 8 | 9 | /* 10 | * Complete the connectingTowns function below. 11 | */ 12 | static int connectingTowns(int n, int[] routes) { 13 | /* 14 | * Write your code here. 15 | */ 16 | int numTower= n-1; 17 | int tot=1; 18 | for(int i=0;i=0; a_i--){ 18 | diff+=a[i][a_i]; 19 | i++; 20 | } 21 | System.out.println(Math.abs(sum-diff)); 22 | } 23 | 24 | public static void main(String[] args) { 25 | Scanner in = new Scanner(System.in); 26 | int n = in.nextInt(); 27 | int a[][] = new int[n][n]; 28 | for(int a_i=0; a_i < n; a_i++){ 29 | for(int a_j=0; a_j < n; a_j++){ 30 | a[a_i][a_j] = in.nextInt(); 31 | } 32 | } 33 | abs_sum(n,a); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /FizzBuzz/ReadME.md: -------------------------------------------------------------------------------- 1 | Write a program to print the numbers from 1 to N, each on a new line, but for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. 2 | 3 | Input 4 | single integer N. 5 | Output 6 | N lines with one integer or string per line as described above. 7 | Constraints : 8 | 0 < N < 107 9 | 10 | -------------------------------------------------------------------------------- /FizzBuzz/myCode.java: -------------------------------------------------------------------------------- 1 | /* package whatever; // don't place package name! */ 2 | 3 | import java.io.*; 4 | 5 | class myCode 6 | { 7 | public static void main (String[] args) throws java.lang.Exception 8 | { 9 | int num; 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | do{ 12 | String input = br.readLine(); 13 | //System.out.println(input); 14 | num=Integer.parseInt(input); 15 | }while(num<0 && num>107); 16 | 17 | for(int i=1;i<=num;i++){ 18 | if(i%3==0 && i%5==0) 19 | System.out.println("FizzBuzz"); 20 | else if(i%3==0) 21 | System.out.println("Fizz"); 22 | else if(i%5==0) 23 | System.out.println("Buzz"); 24 | else 25 | System.out.println(i); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Handshake/Handshake.Java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.text.*; 4 | import java.util.*; 5 | import java.util.regex.*; 6 | 7 | public class Handshake { 8 | 9 | /* 10 | * Complete the handshake function below. 11 | */ 12 | static int handshake(int n) { 13 | /* 14 | * Write your code here. 15 | */ 16 | //if(n<=1) return 0; else 17 | if(n%2==0) // even 18 | {return (n*(n-1)/2);} 19 | else //odd 20 | return (n)*(n/2); 21 | /*4-->6 22 | 5-->10 23 | 6-->15*/ 24 | 25 | } 26 | 27 | private static final Scanner scanner = new Scanner(System.in); 28 | 29 | public static void main(String[] args) throws IOException { 30 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 31 | 32 | int t = Integer.parseInt(scanner.nextLine().trim()); 33 | 34 | for (int tItr = 0; tItr < t; tItr++) { 35 | int n = Integer.parseInt(scanner.nextLine().trim()); 36 | 37 | int result = handshake(n); 38 | 39 | bufferedWriter.write(String.valueOf(result)); 40 | bufferedWriter.newLine(); 41 | } 42 | 43 | bufferedWriter.close(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Handshake/ReadME.md: -------------------------------------------------------------------------------- 1 | See https://www.hackerrank.com/challenges/handshake/problem -------------------------------------------------------------------------------- /Hourglass2DArrays/Hourglass2DArrays.java: -------------------------------------------------------------------------------- 1 | package Hourglass2DArrays; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | import java.text.*; 6 | import java.math.*; 7 | import java.util.regex.*; 8 | 9 | public class Hourglass2DArrays { 10 | 11 | public static void main(String[] args) { 12 | Scanner in = new Scanner(System.in); 13 | int arr[][] = new int[6][6]; 14 | for(int i=0; i < 6; i++){ 15 | for(int j=0; j < 6; j++){ 16 | arr[i][j] = in.nextInt(); 17 | } 18 | } 19 | int max=Integer.MIN_VALUE,sum=0; 20 | //total number (n-(k-1))^d 21 | //d=2,n=6,k=3; 22 | int conta=1; 23 | for(int h=0;h<(4);h++){ 24 | for(int k=0;k<(4);k++){ 25 | for(int i=0+h; i < (3+h); i++){ 26 | for(int j=0+k; j < (3+k); j++){ 27 | System.out.print(arr[i][j]+"("+i+","+j+") "); 28 | sum+=arr[i][j]; 29 | }System.out.println(""); 30 | } 31 | sum=sum-arr[h+1][k]-arr[h+1][k+2]; 32 | System.out.println("----------"+(conta++)+"----------;"+sum+"="+arr[h+1][k]+"+"+arr[h+1][k+2]); 33 | if(maxlengthA) return mergeStrings+=b.substring(i,lengthB); 13 | if((i+1)>lengthB) return mergeStrings+=a.substring(i,lengthA); 14 | mergeStrings+=a.substring(i,i+1); 15 | mergeStrings+=b.substring(i,i+1); 16 | 17 | 18 | }return mergeStrings;} 19 | 20 | public static void main(String[] args){ 21 | Scanner sc= new Scanner(System.in); 22 | 23 | System.out.println(merge(sc.nextLine(),sc.nextLine())); 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /MiniMaxSum/MiniMaxSum.java: -------------------------------------------------------------------------------- 1 | package MiniMaxSum; 2 | import java.io.*; 3 | import java.util.*; 4 | import java.text.*; 5 | import java.math.*; 6 | import java.util.regex.*; 7 | 8 | public class MiniMaxSum { 9 | 10 | public static void main(String[] args) { 11 | long min=Long.MAX_VALUE,max=0,somma=0; 12 | Scanner in = new Scanner(System.in); 13 | long[] arr = new long[5]; 14 | for(int arr_i=0; arr_i < 5; arr_i++){ 15 | arr[arr_i] = in.nextLong(); 16 | } 17 | for(int arr_i=0; arr_i < 5; arr_i++){ 18 | somma+=arr[arr_i]; 19 | if(min>=arr[arr_i]) min=arr[arr_i]; 20 | if(max<=arr[arr_i]) max=arr[arr_i]; 21 | } 22 | 23 | System.out.print(somma-max); //min value possible 24 | System.out.print(" "+(somma-min)); //max value possible 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /OddEvenString/StringOddEven.java: -------------------------------------------------------------------------------- 1 | package OddEvenString; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | import java.text.*; 6 | import java.math.*; 7 | import java.util.regex.*; 8 | 9 | //Split a string in two with character in odd and even position 10 | public class StringOddEven { 11 | public static String printString(String s){ 12 | String s_even=new String(); 13 | String s_odd =new String(); 14 | for(int i=0;i= 0; i--){ 24 | reverse = reverse + parts[k].charAt(i); 25 | } 26 | if(reverseAll.length()==0) 27 | reverseAll=reverse; 28 | else 29 | reverseAll=reverseAll+" "+reverse; 30 | reverse=""; 31 | } 32 | System.out.println(reverseAll); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Staircase/Staircase.java: -------------------------------------------------------------------------------- 1 | package Staircase; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | import java.text.*; 6 | import java.math.*; 7 | import java.util.regex.*; 8 | 9 | public class Staircase { 10 | 11 | public static void main(String[] args) { 12 | Scanner in = new Scanner(System.in); 13 | int n = in.nextInt(); 14 | 15 | String[][] matrix = new String[n][n]; 16 | for(int i=0;i=n-1-j) //i==n-1 || j==n-1 || 19 | matrix[i][j]="#"; 20 | else 21 | matrix[i][j]=" "; 22 | } 23 | } 24 | 25 | for(int i=0;i2*1000000000); 40 | do{ 41 | c = Integer.parseInt(rc[1]); 42 | }while(c>6); 43 | 44 | long result = strangeGrid(r, c); 45 | 46 | bufferedWriter.write(String.valueOf(result)); 47 | bufferedWriter.newLine(); 48 | 49 | bufferedWriter.close(); 50 | 51 | scanner.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /StringAscendingOrder/ReadME.md: -------------------------------------------------------------------------------- 1 | Write a program that takes input of an integer N. Followed by N strings. It then outputs those N strings in ascending order. 2 | Constraints 3 | 0 < Words in Sentence <=100 4 | Your output lines should not have any trailing or leading whitespaces 5 | Upper case alphabets are considered "smaller" than lower case alphabets. -------------------------------------------------------------------------------- /StringAscendingOrder/myCode.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class myCode 4 | { 5 | public static void main (String[] args) throws java.lang.Exception 6 | { 7 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | String input = "3";//br.readLine(); 9 | //String line = "quick brown Fox";//br.readLine(); 10 | String line = "quick Brown Fox";//br.readLine(); 11 | 12 | int N; 13 | //System.out.println(input); 14 | do{ 15 | N = Integer.parseInt(input); 16 | }while(N<0 && N>=100); 17 | String[] sentences=new String[N]; 18 | sentences=line.split(" "); 19 | String temp; 20 | for (int i = 0; i < N; i++) 21 | { 22 | for (int j = i + 1; j < N; j++) 23 | { 24 | if (sentences[i].compareTo(sentences[j])>0) 25 | { 26 | temp = sentences[i]; 27 | sentences[i] = sentences[j]; 28 | sentences[j] = temp; 29 | } 30 | } 31 | } 32 | for(int i=0;i