#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




Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number.


! Keep in mind that your task is to help Bob solve a real IQ test, which means indexes of the elements start from 1 (not 0)


##Examples :


iqTest("2 4 7 8 10") => 3 // Third number is odd, while the rest of the numbers are even


iqTest("1 2 1 1") => 2 // Second number is even, while the rest of the numbers are odd



 #69  Weight for weight


My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.


I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.


For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99. Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?


Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: "100 180 90 56 65 74 68 86 99"


When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.


All numbers in the list are positive numbers and the list can be empty.




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.




#66 Inside Out Strings


You are given a string of words (x), for each word within the string you need to turn the word 'inside out'. By this I mean the internal letters will move out, and the external letters move toward the centre.


If the word is even length, all letters will move. If the length is odd, you are expected to leave the 'middle' letter of the word where it is.


An example should clarify:


'taxi' would become 'atix' 'taxis' would become 'atxsi'



#65 Split Strings 


Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').


Examples:


solution('abc') // should return ['ab', 'c_']

solution('abcdef') // should return ['ab', 'cd', 'ef']



#64 Strip Comments


Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out.


Example:


Given an input string of:


apples, pears # and bananas

grapes

bananas !apples

The output expected would be:


apples, pears

grapes

bananas

The code would be called like so:


var result = solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"])

// result should == "apples, pears\ngrapes\nbananas"




+ Recent posts