Skip to main content

Posts

Showing posts with the label 30 Days Of Code Hackerrank

Day 22: Binary Search Trees Hackerrank Solution Java

 Day 22: Binary Search Trees Hackerrank Solution Java For Explanation Check Video: Sample Input 7 3 5 2 1 4 6 7 Sample Output 3 Code: import  java.util.*; import  java.io.*; class  Node{     Node left,right;      int  data;     Node( int  data){          this .data=data;         left=right=null;     } } class  Solution{      public   static   int  getHeight(Node root){        if (root==null){            return  - 1 ;       }        int  leftHeight = getHeight(root.left);        int  rightHeight = getHeight(root.right);      ...

Day 28: RegEx, Patterns, and Intro to Databases Hackerrank Solution Java

 Day 28: RegEx, Patterns, and Intro to Databases  For Explanation Check Video: Sample Input 6 riya riya@gmail.com julia julia@julia.me julia sjulia@gmail.com julia julia@gmail.com samantha samantha@gmail.com tanya tanya@gmail.com Sample Output julia julia riya samantha tanya 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 {      private   static   final  Scanner scanner =  new  Scanner(System.in);      public   static   void  main(String[] args) {          int  N = scanner.nextInt();         scanner.skip( "(\r\n|[\n\r\u2028\u2029\u0085])?" );         ...

Day 27: Testing Hackerrank Solution Java

 Day 27: Testing Hackerrank Solution Java For Explanation Check Video: Code: import  java.util.*; public   class  Solution {      public   static   int  minimum_index( int [] seq) {          if  (seq.length ==  0 ) {              throw   new  IllegalArgumentException( "Cannot get the minimum value index from an empty sequence" );         }          int  min_idx =  0 ;          for  ( int  i =  1 ; i < seq.length; ++i) {              if  (seq[i] < seq[min_idx]) {    ...

Day 26: Nested Logic Hackerrank Solution Java

 Day 26: Nested Logic Hackerrank Solution Java For Explanation Check Video: Sample Input STDIN Function ----- -------- 9 6 2015 day = 9, month = 6, year = 2015 (date returned) 6 6 2015 day = 6, month = 6, year = 2015 (date due) Sample Output 45 Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  actualDay = scn.nextInt();          int  actualMonth = scn.nextInt();          int  actualYear = scn.nextInt();          int  exceptedDay = scn.nextInt();        ...

Day 25: Running Time and Complexity Hackerrank Solution Java

 Day 25: Running Time and Complexity  For Explanation Check Video: Sample Input 3 12 5 7 Sample Output Not prime Prime Prime 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();          while (t--> 0 ){              int  n = scn.nextInt();              if (n== 1  || n< 1 ){                 System.out.println( "Not prime" );         ...

Day 24: More Linked Lists Hackerrank Solution Java

 Day 24: More Linked Lists Hackerrank  For Explanation Check Video: Sample Input 6 1 2 2 3 3 4 Sample Output 1 2 3 4 Code: import  java.io.*; import  java.util.*; class  Node{      int  data;     Node next;     Node( int  d){         data=d;         next=null;     }      } class  Solution {      public   static  Node removeDuplicates(Node head) {        //Write your code here        if (head==null){            return  null;       }       Node temp = head;        while (temp.next!=null){ ...

Day 23: BST Level-Order Traversal Hackerrank Solution Java

 Day 23: BST Level-Order Traversal For Explanation Check Video:   Sample Input 6 3 5 4 7 2 1 Sample Output 3 2 5 1 4 7 Code: import  java.util.*; import  java.io.*; class  Node{     Node left,right;      int  data;     Node( int  data){          this .data=data;         left=right=null;     } } class  Solution{ static   void  levelOrder(Node root){        Queue<Node> queue =  new  LinkedList<>();     queue.add(root);      while (queue.peek()!=null){         Node node = queue.remove();         System.out.print(node.data+ " " );       ...