Skip to main content

Posts

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;     } }