Skip to main content

Posts

Showing posts from June, 2021

Reverse a Stack using Recursion

 Reverse a Stack using Recursion Code:: import java.util.Stack; public class Test { public static void main(String[] args) { Stack<Integer> st = new Stack<Integer>(); st.add(1); st.add(2); st.add(3); st.add(4); System.out.println(st); reverse(st); System.out.println(st); } public static void reverse(Stack<Integer> s) { if(s.size()==0) { return; } int temp = s.pop(); reverse(s); insert(s,temp); } public static void insert(Stack<Integer> s,int temp) { if(s.size()==0) { s.push(temp); return; } int temp1 = s.pop(); insert(s,temp); s.push(temp1); } }

Mini-Max Sum Hackerrank Solution - java

 Mini-Max Sum Hackerrank Solution - java For Explanation Watch the 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 'miniMaxSum' function below.      *      * The function accepts INTEGER_ARRAY arr as parameter.      */     public static void miniMaxSum(List<Integer> arr) {         Collections.sort(arr);         long sum = 0;         for(int i=0;i<arr.size();i++){             sum += arr.get(i);         }         long low_sum = sum - arr.get(arr.size(...

pgadmin 4 fatal error the application server could not be contacted Solved

 pgadmin 4 fatal error the application server could not be contacted Solved For Detailed Process Watch Video:: Steps to solve the error pgadmin 4 fatal error the application server could not be contacted 1 step :: go to control panal 2 step : click on program and fetures 3 step : click on postgreySQl 4 step::click on uninstall and change 5 step :: choose individual component 6 step :: choose pgadmin and click on next and wait until delete completed 7 step : download pgadmin::       https://www.postgresql.org/ftp/pgadmin/pgadmin4/v5.4/windows/

Cats and a Mouse Hackerrank Solution - java

Cats and a Mouse 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 {     // Complete the catAndMouse function below.     static String catAndMouse(int x, int y, int z) {         int aCat = Math.abs(z-x);         int bCat = Math.abs(z-y);         if(aCat==bCat){             return "Mouse C";         }else if(aCat<bCat){             return "Cat A";         }else{             return "Cat B";         }     }     private static final Scanner scanner = new Scanner(System.in);     public static void main(String[] args) throws IOException { ...

CamelCase Hackerrank Solution - java

CamelCase 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 'camelcase' function below.      *      * The function is expected to return an INTEGER.      * The function accepts STRING s as parameter.      */     public static int camelcase(String s) {//saveChangesInTheEditor        long count = s.chars().filter(ch->ch>=65 && ch<=90).count();        return (int)(count+1);     } } public class Solution {     public static void main(String[] ar...

Mars Exploration Hackerrank Solution - java

 Mars Exploration 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 'marsExploration' function below.      *      * The function is expected to return an INTEGER.      * The function accepts STRING s as parameter.      */     public static int findDifferentLetters(String s){         int count = 0;         if(s.charAt(0)!='S'){             count++;         }          if(s.charAt(1)!='O'){  ...

Delete Nth node from the end of the given linked list Solution - java

 Delete Nth node from the end of the given linked list Solution . For Explanation Watch Video : Code:: class Solution {     public ListNode removeNthFromEnd(ListNode head, int n) {         int count = 0;//5         ListNode temp1 = head;         while(temp1!=null){             count++;             temp1 = temp1.next;         }         if(count==n){             return head.next;         }         ListNode temp2 = head;         int remove = count - n;//3         int count1 = 0;         while(count1!=remove-1){             temp2 = temp2.next;             count1++;         }         temp2.next...

Find the middle of a given linked list Solution - java

 Find the middle of a given linked list Solution - java For Explanation watch video:  Code:: Function to find Middle element if Head Of Linked List Given class Solution {     int getMiddle(Node head)     {          Node slow = head;          Node fast = head;          while(fast!=null && fast.next!=null){              slow = slow.next;              fast = fast.next.next;          }          return slow.data;     } }

Picking Numbers Hackerrank Solution - java

 Picking Numbers Hackerrank Solution - java  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 {          int [] arr =  new   int [ 100 ];         Scanner scn =  new  Scanner(System.in);          int  n = scn.nextInt();          for ( int  i= 0 ;i<...

Simple Array Sum Hackerrank Solution - java

 Simple Array Sum 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 'simpleArraySum' function below.      *      * The function is expected to return an INTEGER.      * The function accepts INTEGER_ARRAY ar as parameter.      */     public static int simpleArraySum(List<Integer> ar) {     // Write your code here     int sum = 0;     for(int i=0;i<ar.size();i++){         sum = sum + ar.get(i);     }     return sum;     } } pub...

java comparator hackerrank solution - java

 java comparator hackerrank solution - java For Explanation Watch Video : Code:: import  java.util.*; // Write your Checker class here class  Checker  implements  Comparator<Player>{      @Override      public   int  compare(Player p1,Player p2){         String name1 = p1.name;         String name2 = p2.name;          int  score1 = p1.score;          int  score2 = p2.score;          if (score1<score2){              return   1 ;         } else   if (score1>score2){       ...

remove duplicate words from string in java

 remove duplicate words from string in java For Explanation Watch Video:  Program:: import java.util.*; class College { public static void main(String[] args){ String sen = " Sam went went to to to his business "; String[] arr = sen.split(" "); //arr={Sam,went,went,to,to ,to ,his ,business}; Set<String> s = new LinkedHashSet<String>(); for(int i=0;i<arr.length;i++){ s.add(arr[i]); } for(String ss:s){ System.out.print(ss+" "); } System.out.println(); } } o/p:  Sam went to his business Using Java 8 import java.util.*; class College { public static void main(String[] args){ String sen = "Sam went went to to to his business"; sen = Arrays.stream(sen.split(" ")).distinct().collect(Collectors.joining(" "); } }

Drawing Book Hackerrank Solution - Java

Drawing Book 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 'pageCount' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER n      *  2. INTEGER...

Introduction to Sets Hackerrank Solution Python

 Introduction to Sets Hackerrank Solution Python code:: def  average(array):      # your code goes here     s =  set ()      for  i  in  array:         s.add(i)      return   sum (s)/ len (s) if  __name__ ==  '__main__' :     n =  int ( input ())     arr =  list ( map ( int ,  input ().split()))     result = average(arr)      print (result)

Counting Valleys Hackerrank Solution - Java

 Counting Valleys 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 'countingValleys' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER steps      * ...

Hackerrank Grading Students Solution - Java

Hackerrank Grading Students 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 'gradingStudents' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY grades as parameter.      */      public   static  Li...

Hackerrank Bill Division Solution - Java

Hackerrank Bill Division 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 'bonAppetit' function below.      *      * The function accepts following parameters:      *  1. INTEGER_ARRAY bill      *  2. INTEGER k      *  3. INTEGER b      */ ...

Hackerrank Breaking the Records Solution - Java

Hackerrank Breaking the Records 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 'breakingRecords' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY scores as parameter.      */      public   stat...

Hackerrank Playing With Characters Solution in c

 Hackerrank Playing With Characters Solution in c Watch Video: Code:: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */           //first step is to create variables      char  ch; //character      char  s[ 128 ]; //for string with maximum size i.e 128      char  sen[ 128 ]; //sentence           //second step for scanning     scanf( "%c" ,&ch); //for charaacter     scanf( "%s\n" ,&s); //for string     scanf( "%[^\...

Hackerrank hello world solution in c

Hackerrank hello world solution in c Watch Video: Code:: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {           char  s[ 100 ];     scanf( "%[^\n]%*c" , &s);           /* Enter your code here. Read input from STDIN. Print output to STDOUT */        printf( "Hello, World!\n" );     printf( "%s" ,s);           return   0 ; }

Hackerrank Divisible Sum Pairs Solution - Java

 Hackerrank Divisible Sum Pairs 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 'divisibleSumPairs' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER n      * ...

Hackerrank Subarray Division Solution - Java

 Hackerrank Subarray Division 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 'birthday' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER_ARRAY s      *  ...

Hackerrank Between Two Sets Hackerrank Solution - Java

 Hackerrank Between Two Sets 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 'getTotalX' function below.      *      * The function is expected to return an INTEGER.      * The function accepts following parameters:      *  1. INTEGER_ARRAY a      *...