Skip to main content

Posts

Showing posts with the label Hackerrank

java map hackerrank solution - Java 15

   java map 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  n = scn.nextInt();         scn.nextLine();         HashMap<String,Integer> hm =  new  HashMap<>();          for ( int  i= 0 ;i<n;i++){             String name = scn.nextLine();              int  mobile = scn.nextInt();             scn.nextLine();             hm.put(name,mobile);         }          while (scn.hasNext()){             String name = scn.nextLine();              if (hm.containsKey(name)){                 System.out.println(name+ "=" +hm.get(name));             } else {                 System.out.println( "Not found" );             }         }        } }

Welcome to Java! hackerrank solution - java

  Welcome to Java! hackerrank solution - java  for explanation watch video: Code: import java.io.*; import java.util.*; public class Solution {     public static void main(String[] args) {        System.out.println("Hello, World.");         System.out.println("Hello, Java.");     } }

Java Stdin and Stdout I hackerrank solution - java

 Java Stdin and Stdout I hackerrank solution - java  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  a = scn.nextInt();          int  b = scn.nextInt();          int  c = scn.nextInt();         System.out.println(a);         System.out.println(b);         System.out.println(c);     } }

Java Varargs - Simple Addition hackerrank Solution - Java

 Java Varargs - Simple Addition hackerrank Solution - Java  for explanation watch video : Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  add( int ... arr){          int  sum =  0 ;          for ( int  i= 0 ;i<arr.length;i++){             sum = sum + arr[i];              if (i==arr.length- 1 ){                 System.out.print(arr[i]+ "=" );             } else {                 System.out.print(arr[i]+ "+" );             }         }         System.out.println(sum);     }      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int [] arr =  new   int [ 6 ];          for ( int  i= 0 ;i< 6 ;i++){             arr[i] = scn.nextInt();         }         add(arr[ 0 ],arr[ 1 ]);         add(arr[ 0 ],arr[ 1 ],arr[ 2 ]);         add(arr[ 0 ],arr[ 1 ],arr[ 2 ],arr[ 3 ],arr[ 4 ]);         add(arr[ 0 ],arr[ 1 ],arr[ 2 ],arr[ 3 ],arr[ 4 ],arr[ 5 ]);     } }

Maximum Perimeter Triangle Hackerrank Solution - java

 Maximum Perimeter Triangle 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 'maximumPerimeterTriangle' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY sticks as parameter.      */      public   static  List<Integer> maximumPerimeterTriangle(List<Integer> sticks) {         Collections.sort(sticks);         ArrayList<Integer> al =  new  ArrayList<>();          int  i = sticks.size()- 3 ;          while (i>= 0 ){              if (sticks.get(i)+sticks.get(i+ 1 )>sticks.get(i+ 2 )){            

Weather Observation Station 13 Hackerrank Solution - SQL

 Weather Observation Station 13 Hackerrank Solution - SQL For Explanation Watch Video :  Code : select round(sum(LAT_N),4) from station where LAT_N > 38.7880 and LAT_N < 137.2345;

Top Earners Hackerrank Solution - SQL | Hackerrank SQL

 Top Earners Hackerrank Solution - SQL for explanation watch video : Code :: select max(salary * months ),count(*) from Employee where salary*months = (select max(salary*months) from Employee);

Grid Challenge Hackerrank Solution - java | Hackerrank Algorithm

 Grid Challenge 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  String sort(String s){          char [] ch = s.toCharArray();         Arrays.sort(ch);          return   new  String(ch);     }      public   static  String gridChallenge(List<String> grid) {                  ArrayList<String> al =  new  ArrayList<>();          for ( int  i= 0 ;i<grid.size();i++){             String s = sort(grid.get(i));             al.add(s);         }                 int  size = al.get( 0 ).length();          for ( int  i= 1 ;i<al.size();i++){              for ( int  j= 0 ;j<size;j++){      

Two Strings Hackerrank Solution - java

 Two Strings 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 'twoStrings' function below.      *      * The function is expected to return a STRING.      * The function accepts following parameters:      *  1. STRING s1      *  2. STRING s2      */     public static String twoStrings(String s1, String s2) {         HashSet<Character> hs = new HashSet<>();         for(Character ch : s1.toCharArray()){             hs.add(ch);         }         for(Character ch : s2.toCharArray()){             if(hs.contains(ch)){                 return "YES";             }         }         return "N

Sum and Difference of Two Numbers Hackerrank Solution - C Language

 Sum and Difference of Two Numbers Hackerrank Solution - C Language  Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  a,b;      float  c,d;     scanf( "%d %d %f %f" ,&a,&b,&c,&d);      int  sum1 = a+b;      int  diff1 = a-b;      float  sum2 = c+d;      float  diff2 = c-d;     printf( "%d %d\n" ,sum1,diff1);     printf( "%.1f %.1f" ,sum2,diff2);      return   0 ; }

Conditional Statements in C Hackerrank Solution - C Language

 Conditional Statements in C Hackerrank Solution - C Language Code: #include   < assert.h > #include   < limits.h > #include   < math.h > #include   < stdbool.h > #include   < stddef.h > #include   < stdint.h > #include   < stdio.h > #include   < stdlib.h > #include   < string.h > char * readline(); int  main() {      char * n_endptr;      char * n_str = readline();      int  n = strtol(n_str, &n_endptr,  10 );      if  (n_endptr == n_str || *n_endptr !=  ' \ 0 ' ) { exit(EXIT_FAILURE); }      // Write Your Code Here      if (n== 1 ){         printf( "one" );     } else   if (n== 2 ){         printf( "two" );     } else   if (n== 3 ){         printf( "three" );     } else   if (n== 4 ){         printf( "four" );     } else   if (n== 5 ){         printf( "five" );     } else   if (n== 6 ){         printf( "six" );     } else   if (n== 7 ){         printf( "s

1D Arrays in C Hackerrank Solution - C Language

  1D Arrays in C Hackerrank Solution - C Language  Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  n;     scanf( "%d" ,&n);      int  arr[n];      int  sum =  0 ;      for ( int  i= 0 ;i<n;i++){         scanf( "%d" ,&arr[i]);         sum = sum + arr[i];     }       printf( "%d" ,sum);      return   0 ; }

Print in Reverse Hackerrank Solution - java

 Print in Reverse 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.regex.*; public   class  Solution {      static   class  SinglyLinkedListNode {          public   int  data;          public  SinglyLinkedListNode next;          public  SinglyLinkedListNode( int  nodeData) {              this .data = nodeData;              this .next = null;         }     }      static   class  SinglyLinkedList {          public  SinglyLinkedListNode head;          public  SinglyLinkedListNode tail;          public  SinglyLinkedList() {              this .head = null;              this .tail = null;         }          public   void  insertNode( int  nodeData) {             SinglyLinkedListNode node =  new  SinglyLinkedListNode(nodeData);              if  ( this .head == null) {                  this .head = node;             }  else  {

For Loop in C Hackerrank Solution - C Language

 For Loop in C Hackerrank Solution - C Language Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {      int  a, b;     scanf( "%d\n%d" , &a, &b);      for ( int  i=a;i<=b;i++){       if (i>= 1  && i<= 9 ){           if (i== 1 ){              printf( "one\n" );          } else   if (i== 2 ){              printf( "two\n" );          } else   if (i== 3 ){              printf( "three\n" );          } else   if (i== 4 ){              printf( "four\n" );          } else   if (i== 5 ){              printf( "five\n" );          } else   if (i== 6 ){              printf( "six\n" );          } else   if (i== 7 ){              printf( "seven\n" );          } else   if (i== 8 ){              printf( "eight\n" );          } else   if (i== 9 ){              printf( "nine\n" );          }    

Sum of Digits of a Five Digit Number Hackerrank Solution - C

 Sum of Digits of a Five Digit Number Hackerrank Solution - C Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {           int  n;     scanf( "%d" , &n);      //Complete the code to calculate the sum of the five digits on n.      int  sum =  0 ;      while (n!= 0 ){          int  r = n% 10 ;         n = n/ 10 ;         sum = sum + r;     }     printf( "%d" ,sum);      return   0 ; }

Functions in C Hackerrank Solution - C Language

 Functions in C Hackerrank Solution - C Language For Explanation Watch Video : Code: #include   < stdio.h > /* Add `int max_of_four(int a, int b, int c, int d)` here. */ int  max_of_four( int  a,  int  b,  int  c,  int  d){      if (a>=b && a>=c && a>=d){          return  a;     } else   if (b>=a && b>=c && b>=d){          return  b;     } else   if (c>=a && c>=b && c>=d){          return  c;     } else {          return  d; //6     } } int  main() {      int  a, b, c, d;     scanf( "%d %d %d %d" , &a, &b, &c, &d);      int  ans = max_of_four(a, b, c, d);     printf( "%d" , ans);           return   0 ; }

Minimum Absolute Difference in an Array HackerRank Solution - java

Minimum Absolute Difference in an Array HackerRank Solution - java   For Explanation Watch Video :  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 'minimumAbsoluteDifference' function below.      *      * The function is expected to return an INTEGER.      * The function accepts INTEGER_ARRAY arr as parameter.      */      public   static   int  minimumAbsoluteDifference(List<Integer> arr) {         Integer min = Integer.MAX_VALUE;         Collections.sort(arr);          for ( int  i= 1 ;i<arr.size();i++){              int  diff = Math.abs(arr.get(i- 1 )-arr.get(i));              if (diff<min){                 min = diff;             }         

Max Min Hackerrank Solution - java

 Max Min 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 'maxMin' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER k      *  2. INTEGER_ARRAY arr      */      public   static   int  maxMin( int  k, List<Integer> arr) {         Collections.sort(arr);         Integer min = Integer.MAX_VALUE;          for ( int  i= 0 ;i<=arr.size()-k;i++){              int  diff = arr.get(i+k- 1 ) - arr.get(i);              if (diff<min){                 min = diff;             }         }          retur

The Report Hackerrank Solution - SQL | Hackerrank SQL

 The Report Hackerrank Solution - SQL For Explanation Watch Video :  Code ::  SELECT CASE        WHEN G.GRADE >= 8 THEN S.NAME        ELSE 'NULL' END,G.GRADE,S.MARKS        FROM STUDENTS S,GRADES G        WHERE S.MARKS >= MIN_MARK AND S.MARKS <=MAX_MARK        ORDER BY G.GRADE DESC,S.NAME,S.MARKS;

Tree: Level Order Traversal Hackerrank Solution - java | Hackerrank Data Structures

 Tree: Level Order Traversal Hackerrank Solution - java For Explanation Watch Video :  Code import  java.util.*; import  java.io.*; class  Node {     Node left;     Node right;      int  data;          Node( int  data) {          this .data = data;         left = null;         right = null;     } } class  Solution {      /*           class Node          int data;         Node left;         Node right;     */      public   static   void  levelOrder(Node root) {         Queue<Node> q =  new  LinkedList<>();          if (root==null){              return ;         }         q.add(root);          while (!q.isEmpty()){             Node temp = q.poll();             System.out.print(temp.data+  " " );              if (temp.left!=null){                 q.add(temp.left);             }              if (temp.right!=null){                 q.add(temp.right);             }         }     }      public   static  Node insert(Node root,  int  data) {          if (root == null) {