Skip to main content

Posts

Showing posts with the label Hackerrank

Population Census hackerrank Solution

Population Census hackerrank Solution for explanation watch video: Code:: select sum(city.population) from city inner join country on CITY.CountryCode = COUNTRY.Code where country.CONTINENT = 'Asia';

Linux Shell - Arithmetic Operations solution

 Linux Shell - Arithmetic Operations solution for explanation watch video:: code:: read string res= $(echo "scale=4;$string" | bc) printf  "%.3f"   "$res"  

Weather Observation Station 19 Hackerrank Solution - SQL

  Weather Observation Station 19 Hackerrank Solution - SQL  for explanation watch video :: Code:: select round(sqrt(     power(max(lat_n)-min(lat_N),2)+     power(max(long_w)-min(long_w),2) ),4) from station;

Weather Observation Station 15 Hackerrank Solution - SQL

 Weather Observation Station 15 Hackerrank Solution - SQL For explanation watch video :: Code:: select round(long_w,4) from station where lat_n = (select max(lat_n) from station where lat_n<137.2345);

Weather Observation Station 14 Hackerrank Solution - SQL

Weather Observation Station 14 Hackerrank Solution - SQL For explanation watch video :: Code:: select round(max(LAT_N),4) from station where LAT_N < 137.2345;

Weather Observation Station 18 Hackerrank Solution - SQL

Weather Observation Station 18 Hackerrank Solution - SQL For explanation watch video :: Code:: select round(abs(max(lat_n)-min(lat_n))+abs(max(long_w)-min(long_w)),4) from station;

Weather Observation Station 17 Hackerrank Solution - SQL

 Weather Observation Station 17 Hackerrank Solution - SQL for explanation watch video :: Code:: select round(long_w,4) from station where lat_n = (select min(lat_n) from station where lat_n>38.7780);

Weather Observation Station 16 Hackerrank Solution - SQL

 Weather Observation Station 16 Hackerrank Solution - SQL  For explanation watch video :: Code:: select round(min(lat_n),4) from station where lat_n>38.7780;

Weather Observation Station 2 Hackerrank Solution - SQL

 Weather Observation Station 2 Hackerrank Solution - SQL For Explanation watch video::: Code:: select round(sum(LAT_N),2),round(sum(LONG_W),2) from station;

Modified Kaprekar Numbers Hackerrank Solution - java

 Modified Kaprekar Numbers Hackerrank Solution - java For explanation watch video : Code:: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'kaprekarNumbers' function below.      *      * The function accepts following parameters:      *  1. INTEGER p      *  2. INTEGER q      */     public static void kaprekarNumbers(int p, int q) {         ArrayList<Long> al = new ArrayList<>();         for(long i=p;i<=q;i++){             long sq = i*i;             String num = String.valueOf(i);             String s = String.valueOf(sq);             int leftLength = s.length() - num.length();             long leftNum = 0;             if(leftLength == 0){                 lef

equalize the array hackerrank solution in java

 equalize the array hackerrank solution in java for explanation watch video :: code:: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'equalizeArray' function below.      *      * The function is expected to return an INTEGER.      * The function accepts INTEGER_ARRAY arr as parameter.      */     public static int equalizeArray(List<Integer> arr) {                 HashMap<Integer,Integer> hm = new HashMap<>();         for(int i=0;i<arr.size();i++){             hm.put(arr.get(i),hm.getOrDefault(arr.get(i),0)+1);         }                  int max = Integer.MIN_VALUE;         for(Map.Entry<Integer,Integer> e : hm.entrySet()){             int value

Library Fine Hackerrank Solution - java

 Library Fine Hackerrank Solution - java for explanation watch video : code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'libraryFine' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER d1      *  2. INTEGER m1      *  3. INTEGER y1      *  4. INTEGER d2      *  5. INTEGER m2      *  6. INTEGER y2      */      public   static   int  libraryFine( int  d1,  int  m1,  int  y1,  int  d2,  int  m2,  int  y2) {          if (y1>y2){              return   10000 ;         } else   if (m1>m2 && y1==y2){              return   500  *(m1-m2);         } else  

Sequence Equation Hackerrank Solution - java

 Sequence Equation Hackerrank Solution - java  for explanation watch video :: code:: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'permutationEquation' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY p as parameter.      */      public   static  List<Integer> permutationEquation(List<Integer> p) {          // p = [4 3 5 1 2]           //     1 2 3 4 5          //1)size of arry          int  n = p.size(); //5          //2)find index of 1 to n in arraylist p         ArrayList<Integer> al1 =  new  ArrayList<>();          for ( int  i= 1 ;i<=n;i++){       

Chocolate Feast Hackerrank Solution - java

Chocolate Feast Hackerrank Solution - java for explanation watch video : code: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'chocolateFeast' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER n      *  2. INTEGER c      *  3. INTEGER m      */     public static int chocolateFeast(int n, int c, int m) {         //no of  chocolate          int num = n/c;         int wrapper = num;         if(wrapper<m){             return num;         }else{             while(wrapper>=m){                 num = num + 1;                 wrapper = wrapper - m + 1;             }             ret

Sherlock and Squares Hackerrank Solution - java

Sherlock and Squares Hackerrank Solution - java For explanation watch video :: Code:: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      public   static   int  squares( int  a,  int  b) {          int  first = ( int )Math.ceil(Math.sqrt(a));          int  last = ( int )Math.floor(Math.sqrt(b));          return  last - first + 1 ;     } } public   class  Solution {      public   static   void  main(String[] args)  throws  IOException {         BufferedReader bufferedReader =  new  BufferedReader( new  InputStreamReader(System.in));         BufferedWriter bufferedWriter =  new  BufferedWriter( new  FileWriter(System.getenv( "OUTPUT_PATH" )));          int  q = Integer.parseInt(buffe

Diagonal Difference Hackerrank Solution - java

 Diagonal Difference Hackerrank Solution - java for explanation watch video : Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'diagonalDifference' function below.      *      * The function is expected to return an INTEGER.      * The function accepts 2D_INTEGER_ARRAY arr as parameter.      */      public   static   int  diagonalDifference(List<List<Integer>> arr) {          int  size = arr.get( 0 ).size();          int  sum1 =  0 ;          for ( int  i= 0 ;i<size;i++){              for ( int  j= 0 ;j<size;j++){                  if (i==j){                     sum1 = sum1 + arr.get(i).get(j);                 }             }         }

The Blunder Hackerrank Solution - SQL

 The Blunder Hackerrank Solution - SQL For explanation watch video :: Code: select ceil(avg(salary)-avg(replace(salary,'0',''))) from Employees;

java hashset hackerrank solution - java 15

 java hashset hackerrank solution - java 15 for explanation watch video: code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  t = scn.nextInt();         scn.nextLine();         HashSet<String> hs =  new  HashSet<>();          for ( int  i= 0 ;i<t;i++){             String s = scn.nextLine();             hs.add(s);             System.out.println(hs.size());         }     } }