Skip to main content

Posts

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 : Top View Hackerrank Solution - java

Tree : Top View Hackerrank Solution 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;     */      static   class  NodeLevel{         Node node;         Integer level;         NodeLevel(Node node,Integer level){              this .node = node;              this .level = level;         }     }      public   static   void  topView(Node root) {         Queue<NodeLevel> q =  new  LinkedList<>();         TreeMap<Integer,Integer> tm =  new  TreeMap<>();          if (root==null){              return ;         }         q.add( new  NodeLevel(root, 0 ));          while (!q.isEmpty()){             NodeLevel temp = q.poll();             Node temp1 = temp.node;             Intege

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) {    

Hash Tables: Ransom Note Hackerrank Solution - java | Hackerrank

 Hash Tables: Ransom Note 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 'checkMagazine' function below.      *      * The function accepts following parameters:      *  1. STRING_ARRAY magazine      *  2. STRING_ARRAY note      */      public   static   void  checkMagazine(List<String> magazine, List<String> note) {          //two times three is not four          //two times two is four         HashMap<String,Integer> hm =  new  HashMap<>();          for ( int  i= 0 ;i<magazine.size();i++){             String s = magazine.get(i);             hm.put(s,hm.getOrDefault