Skip to main content

Posts

Showing posts from April, 2021

Mutations Hackerrank Solution Python

Mutations Hackerrank Solution Python  For Explanation Watch Video:: def  mutate_string(string, position, character):      return string[:position] + character + string[position+1:]  if  __name__ ==  '__main__' :     s =  input ()     i, c =  input ().split()     s_new = mutate_string(s,  int (i), c)      print (s_new)

Capitalize! Hackerrank Solution Python

 Capitalize! Hackerrank Solution Python For Explanation Watch Video:: Code: #!/bin/python3 import  math import  os import  random import  re import  sys # Complete the solve function below. def  solve(s):                                for x in s[:].split():         s = s.replace(x,x.capitalize())      return s if  __name__ ==  '__main__' :     fptr =  open (os.environ[ 'OUTPUT_PATH' ],  'w' )     s =  input ()     result = solve(s)     fptr.write(result +  '\n' )     fptr.close()

Java Date and Time Hackerrank Solution

 Java Date and Sample Input For Explanation Watch Video: Sample Input 08 05 2015 Sample Output WEDNESDAY 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 'findDay' function below.      *      * The function is expected to return a STRING.      * The function accepts following parameters:      *  1. INTEGER month    ...

Java BitSet Hackerrank Solution

 Java BitSet Hackerrank Solution For Explanation Watch Video: Sample Input 5 4 AND 1 2 SET 1 4 FLIP 2 2 OR 2 1 Sample Output 0 0 1 0 1 1 1 2 Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner s =  new  Scanner(System.in);          int  n = s.nextInt();          int  m = s.nextInt();         BitSet b1 =  new  BitSet(n);         BitSet b2 =  new  BitSet(n);          for ( int  i= 0 ;i<m;i++){             String ip = s.next...

Java Method Overriding 2 (Super Keyword) Hackerrank Solution

 Java Method Overriding 2 (Super Keyword) Hackerrank Solution For Explanation Watch Video: import  java.util.*; import  java.io.*; class  BiCycle{     String define_me(){          return   "a vehicle with pedals." ;     } } class  MotorCycle  extends  BiCycle{     String define_me(){          return   "a cycle with an engine." ;     }          MotorCycle(){         System.out.println( "Hello I am a motorcycle, I am " + define_me());          String temp=super.define_me(); //Fix this line         System.out.println( "My a...

Java Method Overriding Hackerrank Solution

 Java Method Overriding Hackerrank Solution For Explanation Watch Video: import  java.util.*; class  Sports{     String getName(){          return   "Generic Sports" ;     }         void  getNumberOfTeamMembers(){         System.out.println(  "Each team has n players in "  + getName() );     } } class  Soccer  extends  Sports{      @Override     String getName(){          return   "Soccer Class" ;     }      // Write your overridden getNumberOfTeamMembers method here     @Override     void getNumberOfTeamMembers(){ ...

Java Inheritance II Hackerrank Solution

 Java Inheritance II Hackerrank Solution For Explanation Watch Video: Input Format You are not responsible for reading any input from stdin; a locked code stub will test your submission by calling the  add  method on an  Adder  object and passing it   integer parameters. Output Format You are not responsible for printing anything to stdout. Your  add  method must return the sum of its parameters. Sample Output The  main  method in the  Solution  class above should print the following: My superclass is: Arithmetic 42 13 20 Code: import  java.io.*; import  java.util.*; import  java.text.*; import  java.math.*; import  java.util.regex.*; class  Arithmetic{      public   int  add( int  a, int  b){          return  a+b;     } } class  Adder  extends  Arithmetic{    ...

Java Inheritance I Hakerrank Solution

 Java Inheritance I Hakerrank Solution For Explanation Watch Video: import  java.io.*; import  java.util.*; import  java.text.*; import  java.math.*; import  java.util.regex.*; class  Animal{      void  walk(){         System.out.println( "I am walking" );     } } class  Bird  extends  Animal{      void  fly(){         System.out.println( "I am flying" );     }      void sing(){         System.out.println("I am singing");     } } public   class  Solution{     public   static   void  main(String args[]){       Bird bird =  new  Bird();      ...

Java Generics Hackerrank Solution

Java Generics Hackerrank Solution For Explanation Watch Video: import  java.io.IOException; import  java.lang.reflect.Method; class  Printer {    //Write your code here    public <T> void printArray(T[] arr){        for(int i=0;i<arr.length;i++){            System.out.println(arr[i]);        }    }   } public   class  Solution {      public   static   void  main( String args[] ) {         Printer myPrinter =  new  Printer();         Integer[] intArray = {  1 ,  2 ,  3  };         String[] stringArray =...

Java Anagrams Hackerrank Solution

 Java Anagrams Hackerrank Solution For Explanation Watch Video: Sample Input 1 anagramm marganaa Sample Output 1 Not Anagrams Sample Input 2 Hello hello Sample Output 2 Anagrams Code: import  java.util.Scanner; public   class  Solution {      static   boolean  isAnagram(String a, String b) {          a = a.toLowerCase();         b = b.toLowerCase();         char[] ch1 = a.toCharArray();         char[] ch2 = b.toCharArray();         java.util.Arrays.sort(ch1);         java.util.Arrays.sort(ch2);         String s1 = new String(ch1);      ...

Java Substring Comparisons Hackerrank Solution

 Java Substring Comparisons Hackerrank Solution For Explanation Watch Video: Sample Input 0 welcometojava 3 Sample Output 0 ava wel Code: import  java.util.Scanner; public   class  Solution {      public   static  String getSmallestAndLargest(String s,  int  k) {         String smallest =  "" ;         String largest =  "" ;          smallest = s.substring(0,k);         largest = s.substring(0,k);         for(int i=0;i<=s.length()-k;i++){             String sub = s.substring(i,i+k);             if(smallest.compareTo(sub...

Java Strings Introduction Hackerrank Solution

 Java Strings Introduction Hackerrank Solution For Explanation Watch Video: Sample Input 0 hello java Sample Output 0 9 No Hello Java Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {                  Scanner sc= new  Scanner(System.in);         String A=sc.next();         String B=sc.next();          /* Enter your code here. Print output to STDOUT. */         System.out.println(A.length()+B.length());          if (A.compareTo(B)> 0 ){           ...