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()-1);         long hig_sum = sum - arr.get(0);         System.out.println(low_sum+" "+hig_sum);     } } public class Solution {     public static void main(String[] args) throws IOException {    

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 {         BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));         int q = scanner.nextInt();         scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");         for (in

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[] args) throws IOException {         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));         BufferedWriter bufferedWriter

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'){             count++;         }          if(s.charAt(2)!='S'){             count++;         }         return count;     }     public static int marsExploration(String s) {         int ans = 0;         for

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 = temp2.next.next;         return head;     } }

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<n;i++){              int  num = scn.nextInt();             arr[num]++;         }          int  max =  0 ;          for ( int  i= 0 ;i< 99 ;i++){             max = Math.max(max,arr[i]+arr[i+ 1 ]);         }         System.out.println(max);     } }

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;     } } public class Solution {     public static void main(String[] args) throws IOException {         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));  

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){              return  - 1 ;         } else  {              return  name1.compareTo(name2);         }     } } class  Player{

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 p      */      public   static   int  pageCount( int  n,  int  p) {          return  Math.min(p/ 2 ,(n/ 2 )-(p/ 2 ));     } } public   class  Solution {      public   static   void  main(String[] args)  throws  IOException {         BufferedReader bufferedReader =  new  BufferedReader( new  InputStreamReader(System.in));         BufferedWriter bufferedWriter =

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      *  2. STRING path      */      public   static   int  countingValleys( int  steps, String path) {          int  sum =  0 ;          int  vally =  0 ;          for ( int  i= 0 ;i<steps;i++){              if (path.charAt(i)== 'U' ){                  if (sum==- 1 ){                     vally++;                 }                 sum = sum +  1 ;       

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  List<Integer> gradingStudents(List<Integer> grades) {         ArrayList<Integer> al =  new  ArrayList<>();          for ( int  i= 0 ;i<grades.size();i++){              int  mark = grades.get(i);              if (mark< 38 ){                 al.add(mark);             } else {                  int  multiple = (mark

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      */      public   static   void  bonAppetit(List<Integer> bill,  int  k,  int  b) {          int  sum =  0 ;          for ( int  i= 0 ;i<bill.size();i++){              if (i!=k){                 sum = sum + bill.get(i);             }         }          int  val = sum/ 2 ;          if (val==b){             System.out.println( "Bon Appetit" );         } else

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   static  List<Integer> breakingRecords(List<Integer> scores) {          int  max_count =  0 ;          int  min_count =  0 ;          int  max_value = scores.get( 0 );          int  min_value = scores.get( 0 );          for ( int  i= 1 ;i<scores.size();i++){              int  val = scores.get(i);              if (val>max_value

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( "%[^\n]%*c" ,&sen); //for sentence      //third step for printing     printf( "%c\n" ,ch); //for printing char     printf( "%s\n" ,s); //for printing string     printf( "%s\n" ,sen); //for printing sentence      return   0 ; }

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      *  2. INTEGER k      *  3. INTEGER_ARRAY ar      */      public   static   int  divisibleSumPairs( int  n,  int  k, List<Integer> ar) {          int  ans =  0 ;          for ( int  i= 0 ;i<n;i++){              for ( int  j=i+ 1 ;j<n;j++){                  if ((ar.get(i)+ar.get(j))%k== 0 ){                     ans++;                 }            

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      *  2. INTEGER d      *  3. INTEGER m      */      public   static   int  birthday(List<Integer> s,  int  d,  int  m) {          int  ans =  0 ;          for ( int  i= 0 ;i<=s.size()-m;i++){              int  sum =  0 ;              for ( int  j=i;j<i+m;j++){                 sum = sum + s.get(j);             }              if (sum==d){                

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      *  2. INTEGER_ARRAY b      */      public   static   int  getTotalX(List<Integer> a, List<Integer> b) {         ArrayList<Integer> al =  new  ArrayList<>();          int  first = a.get(a.size()- 1 ); //last element of a          int  last = b.get( 0 ); //first element of b          for ( int  i=first;i<=last;i++){