#83 Stop gninnipS My sdroW!


Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.



Examples:


spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" 

spinWords( "This is a test") => returns "This is a test" 

spinWords( "This is another test" )=> returns "This is rehtona test"


 #75 Numericals of a String


You are given an input string.


For each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it...


But will your code be performant enough?


Examples:

input   =  "Hello, World!"

result  =  "1112111121311"


input   =  "aaaaaaaaaaaa"

result  =  "123456789101112"

Note: there will be no int domain overflow (character occurences will be less than 2 billion).




 #73 Counting Duplicates


Count the number of Duplicates

Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.


Example

"abcde" -> 0 # no characters repeats more than once

"aabbcde" -> 2 # 'a' and 'b'

"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (bandB)

"indivisibility" -> 1 # 'i' occurs six times

"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice

"aA11" -> 2 # 'a' and '1'

"ABBA" -> 2 # 'A' and 'B' each occur twice




#72 Moving Zeros To The End


Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.


moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0]


#71 Triple trouble


Write a function


tripledouble(num1,num2)

which takes in numbers num1 and num2 and returns 1 if there is a straight triple of a number at any place in num1 and also a straight double of the same number in num2.

For example:

tripledouble(451999277, 41177722899) == 1 // num1 has straight triple 999s and 

                                          // num2 has straight double 99s


tripledouble(1222345, 12345) == 0 // num1 has straight triple 2s but num2 has only a single 2


tripledouble(12345, 12345) == 0


tripledouble(666789, 12345667) == 1

If this isn't the case, return 0




Task

You are working for NoVirus Security Solutions and they ask you to make a scanner that scans a file inputted by the user with the function scanFile(File,VirusDB) that takes a File and a VirusDB object and return whether a file is safe or not. Remember: the searches need to be non-Case-Sensitive


Your class also has the function setScanIntensity(int) which changes the scan intensity. This will only receive values 0, 1, 2 or 3. This has been done for you.


The scan intensity determines the arrays from the database that will be used. i.e.:


scanIntensity 0 means off(every file is considered safe)

scanIntensity 1 means that only the array intensity1Signatures will be used

scanIntensity 2 means that the arrays intensity1Signatures and intensity2Signatures will be used

scanIntensity 3 means that all 3 arrays will be used


Outputs

The outputs should be: "Filename is safe" or "Filename is not safe" (Filename is the name of the file that you can get with file.getName() )


File Class


class File{
  private String name;
  private String data;

  public File(String name,String data){
    this.name = name;
    this.data = data;
  }

  //used in output
  public String getName(){
    return this.name;
  }

  //the String that you need to scan.
  public String getData(){
    return this.data;
  }
}


VirusDB Class


class VirusDB{
   private String[] intensity1Signatures;
   private String[] intensity2Signatures;
   private String[] intensity3Signatures;

   public VirusDB(String[] intensity1Signatures,String[] intensity2Signatures,String[] intensity3Signatures){
     this.intensity1Signatures = intensity1Signatures;
     this.intensity2Signatures = intensity2Signatures;
     this.intensity3Signatures = intensity3Signatures;
   }

   public String[] getSignatures(int arrayNum){
     switch (arrayNum){
       case 1:return this.intensity1Signatures;
       case 2:return this.intensity2Signatures;
       case 3:return this.intensity3Signatures;
       default:return new String[0];
     }
   }
}

Examples



 String[] intensity1signatures = new String[]{
        "malware",
        "virus",
        "infect"
      };

      String[] intensity2signatures = new String[]{
        "ransomware",
        "trojan",
        "trojanHorse",
        "worm",
        "spyware",
        "keystrokelogger",
        "adware",
        "botnet",
        "rootkit",
      };

      String[] intensity3signatures = new String[]{
        "DeleteSys32",
        "OverideMBR",
        "EncryptAll",
        "openrandomwebsite",
        "openrandwebsite",
        "sendalldata",
        "recordKeyboard",
        "recordmouse",
        "destroy",
        "overheat",
        "getfullcontrol",
        "uploadharddrive",
        "uploadharddisk",
        "overload",
        "changeOS",
        "encrypt",
        "changeDesktop",
        "ddos",
        "dos",
        "hide",
        "inject",
        "ransom",
        "getcreditcardinfo",
        "getpasswords",
        "getpass",
      };

#67 Predict your age!


My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!


In honor of my grandfather's memory we will write a function using his formula!


Take a list of ages when each of your great-grandparent died.

Multiply each number by itself.

Add them all together.

Take the square root of the result.

Divide by two.

Example

predictAge(65, 60, 75, 55, 60, 63, 64, 45) === 86

Note: the result should be rounded down to the nearest integer.




 #56 Maximum subarray sum


The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:


Max.sequence(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4});

// should be 6: {4, -1, 2, 1}

Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead.


Empty list is considered to have zero greatest sum. Note that the empty list or array is also a valid sublist/subarray.



#48 A Rule of Divisibility by 13


When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions:


1, 10, 9, 12, 3, 4.


Then the whole pattern repeats.


Hence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above, the second right most digit to the second left most digit of the number in the sequence. The cycle goes on and you sum all these products. Repeat this process until the sequence of sums is stationary.


...........................................................................


Example: What is the remainder when 1234567 is divided by 13?


7×1 + 6×10 + 5×9 + 4×12 + 3×3 + 2×4 + 1×1 = 178


We repeat the process with 178:


8x1 + 7x10 + 1x9 = 87


and again with 87:


7x1 + 8x10 = 87


...........................................................................


From now on the sequence is stationary and the remainder of 1234567 by 13 is the same as the remainder of 87 by 13: 9


Call thirt the function which processes this sequence of operations on an integer n (>=0). thirt will return the stationary number.


thirt(1234567) calculates 178, then 87, then 87 and returns 87.


thirt(321) calculates 48, 48 and returns 48




#44 Bouncing Balls


A child plays with a ball on the nth floor of a big building. The height of this floor is known.


(float parameter "h" in meters. Condition 1) : h > 0)


He lets out the ball. The ball bounces for example to two-thirds of its height.


(float parameter "bounce". Condition 2) : 0 < bounce < 1)


His mother looks out of a window that is 1.5 meters from the ground.


(float parameters "window". Condition 3) : window < h).


How many times will the mother see the ball either falling or bouncing in front of the window?


If all three conditions above are fulfilled, return a positive integer, otherwise return -1.


Note


You will admit that the ball can only be seen if the height of the rebouncing ball is stricty greater than the window parameter.


Example:


h = 3, bounce = 0.66, window = 1.5, result is 3


h = 3, bounce = 1, window = 1.5, result is -1 (Condition 2) not fulfilled).



+ Recent posts