Skip to main content

Posts

Showing posts with the label Algorithms

Selection Sort Program in java

 Selection Sort Program in java Code: import java.util.*; import java.lang.*; import java.io.*; class Test{ public static void main(String[] args){ int[] arr = {7,2,4,1,5,3}; selection(arr); for(int i : arr){ System.out.print(i+ " "); } } public static void selection(int[] arr){ for(int i=0;i<arr.length;i++){ int minVal = arr[i]; int ind = i; for(int j= i+1;j<arr.length;j++){ if(arr[j] < minVal){ ind = j; minVal = arr[j]; } } //swap with minimum  int temp = arr[i]; arr[i] = minVal; arr[ind] = temp; } } }

Sequence Equation Hackerrank Solution - java

 Sequence Equation 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 'permutationEquation' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY p as parameter.      */      public   s...

A Very Big Sum Hackerrank Solution - java

 A Very Big 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 'aVeryBigSum' function below.      *      * The function is expected to return a LONG_INTEGER.      * The function accepts LONG_INTEGER_ARRAY ar as parameter.      */     public static long aVeryBigSum(List<Long> ar) {         long sum = 0;         for(int i=0;i<ar.size();i++){             sum = sum + ar.get(i);         }         return sum; ...

Maximum Perimeter Triangle Hackerrank Solution - java

 Maximum Perimeter Triangle 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 'maximumPerimeterTriangle' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY sticks as parameter.      */    ...

Two Strings Hackerrank Solution - java

 Two Strings 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 'twoStrings' function below.      *      * The function is expected to return a STRING.      * The function accepts following parameters:      *  1. STRING s1      *  2. STRING s2      */     public static String twoStrings(String s1, String s2) {         HashSet<Character> hs = new HashSet<>();         for(Character ch : s1.toCharArray()){       ...

Minimum Absolute Difference in an Array HackerRank Solution - java

Minimum Absolute Difference in an Array HackerRank Solution - java   For Explanation Watch Video :  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 'minimumAbsoluteDifference' function below.      *      * The function is expected to return an INTEGER.      * The function accepts INTEGER_ARRAY arr as parameter.      */    ...

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. IN...

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...

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...

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...

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 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 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      *  ...