Skip to main content

Posts

Showing posts from August, 2021

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

Placements Hackerrank Solution SQL | Hackerrank SQL

 Placements Hackerrank Solution SQL For Explanation Watch Video :  Code : SELECT NAME FROM STUDENTS S,FRIENDS F,PACKAGES P1,PACKAGES P2 WHERE S.ID=F.ID AND S.ID=P1.ID AND F.FRIEND_ID=P2.ID AND P1.SALARY < P2.SALARY ORDER BY P2.SALARY;

Jumping on the Clouds Hackerrank Solution - java

 Jumping on the Clouds 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; public   class  Solution {      public   static   void  main(String[] args)  throws  IOException {         Scanner scn =  new  Scanner(System.in);          int  n = scn.nextInt();          int [] arr =  new   int [n];          for ( int  i= 0 ;i<n;i++){             arr[i] = scn.nextInt();         }          if (n== 2  || n== 3 ){             System.out.println( 1 );         } else { // n=6  0 0 0 0 1 0              int  i= 0 ;              int  count =  0 ;              while (i<=n- 2 ){                  if ((i+ 2 )<n && arr[i+ 2 ]!= 1 ){                    

Repeated String Hackerrank Solution - java

 Repeated String 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  noOfA(String s, long  rem){          int  count =  0 ;          for ( int  i= 0 ;i<rem;i++){              if (s.charAt(i)== 'a' ){                 count++;             }         }          return  count;     }      public   static   long  repeatedString(String s,  long  n) {          int  a_count =  0 ;          for ( int  i= 0 ;i<s.length();i++){              if (s.charAt(i)== 'a' ){                 a_count++;             }         }          long  rem = n % s.length();          if (rem== 0 ){              return

Any or All Hackerrank Solution Python | Hackerrank Python

 Any or All Hackerrank Solution Python For Explanation Watch Video :  Code: siz = int(input()) lst = list(input().split()) pos = all([int(i)>0 for i in lst]) pal = any([st == st[::-1] for st in lst]) print(pos and pal)#true 

Program to find the frequency of characters in given string in java

Program to find the frequency of characters in given string in java  For Explanation Watch Video : Code:: import java.util.*; import java.io.*; import java.lang.*; class Test{ public static void main(String[] args) { String name = "idiot"; Map<Character,Integer> map = new HashMap<Character,Integer>(); for(int i=0;i<name.length();i++){ Character ch = name.charAt(i); map.put(ch,map.getOrDefault(ch,0)+1); } System.out.println(map); for(Map.Entry<Character,Integer> e : map.entrySet()){ System.out.println(e.getKey()+" "+e.getValue()); } } } o/p: {d=1, t=1, i=2, o=1} d 1 t 1 i 2 o 1