|
| 1 | +TopCoder Security Agency (TSA, established today) is going to search for dangerous content in the internet. |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +There are N candidate websites numbered 0 through N-1. Each website has an address given as address[i]. It also has one or more keywords associated with it. The i-th element of keyword is a String describing all keywords associated with the i-th website. It is formatted as a single space separated list of keywords without leading or trailing spaces, where each keyword consists only of lowercase letters. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +It is known to TSA that some keywords are dangerous. These keywords are given in String[] dangerous, where each element is a single dangerous keyword. For all other keywords it is not initially known whether they are dangerous or not. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +TSA uses the following algorithm to identify all dangerous websites: |
| 14 | + |
| 15 | + Initially, all websites are considered to be safe. |
| 16 | + |
| 17 | + While there exists a website W such that it's considered safe and |
| 18 | + at least threshold of its keywords are known to be dangerous |
| 19 | + |
| 20 | + Website W becomes dangerous |
| 21 | + All keywords associated with W become dangerous |
| 22 | + |
| 23 | + End While |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Return a String[] containing the addresses of all dangerous websites found by the algorithm described above sorted in increasing order of website numbers. Return an empty String[] if no dangerous website is found. |
| 28 | + |
| 29 | +Definition |
| 30 | + |
| 31 | +Class: InternetSecurity |
| 32 | +Method: determineWebsite |
| 33 | +Parameters: String[], String[], String[], int |
| 34 | +Returns: String[] |
| 35 | +Method signature: String[] determineWebsite(String[] address, String[] keyword, String[] dangerous, int threshold) |
| 36 | +(be sure your method is public) |
| 37 | + |
| 38 | + |
| 39 | +Notes |
| 40 | +- The address of a website is just a String used to uniquely identify it. It doesn't necessarily adhere to any common format of naming websites. |
| 41 | + |
| 42 | +Constraints |
| 43 | +- address will contain between 1 and 50 elements, inclusive. |
| 44 | +- Each element of address will contain between 1 and 50 characters, inclusive. |
| 45 | +- Each character in address will be a '.', '_' or a lowercase letter ('a'-'z'). |
| 46 | +- All elements of address will be distinct. |
| 47 | +- keyword will contain the same number of elements as address. |
| 48 | +- Each element of keyword will contain between 1 and 50 characters, inclusive. |
| 49 | +- Each character in keyword will be a ' ' or a lowercase letter ('a'-'z'). |
| 50 | +- Each element in keyword will be formatted as described in the statement above. |
| 51 | +- For each website, the keywords associated with it will be distinct. |
| 52 | +- dangerous will contain between 1 and 50 elements, inclusive. |
| 53 | +- Each element of dangerous will contain between 1 and 50 characters, inclusive. |
| 54 | +- Each character in dangerous will be a lowercase letter ('a'-'z'). |
| 55 | +- All elements of dangerous will be distinct. |
| 56 | +- threshold will be between 1 and 25, inclusive. |
| 57 | + |
| 58 | +Examples |
| 59 | +0) |
| 60 | + |
| 61 | + |
| 62 | +{"www.topcoder.com", |
| 63 | +"www.sindicate_of_evil.com", |
| 64 | +"www.happy_citizens.com"} |
| 65 | + |
| 66 | +{"hack encryption decryption internet algorithm", |
| 67 | +"signal interference evil snake poison algorithm", |
| 68 | +"flower baloon topcoder blue sky sea"} |
| 69 | + |
| 70 | +{"hack","encryption","decryption","interference","signal","internet"} |
| 71 | + |
| 72 | +3 |
| 73 | + |
| 74 | +Returns: {"www.topcoder.com", "www.sindicate_of_evil.com" } |
| 75 | + |
| 76 | +"www.topcoder.com" is detected as dangerous since it contains four dangerous keywords: "hack", "encryption", "decryption", and "internet". Hence, "algorithm" becomes a dangerous keyword. As a result, "www.sindicate_of_evil.com" is detected as dangerous since it contains three dangerous keywords: "interference", "signal", and "algorithm". Hence, the correct return value is {"www.topcoder.com","www.sindicate_of_evil.com"} since the answer must be sorted in increasing order of website numbers. |
| 77 | +1) |
| 78 | + |
| 79 | + |
| 80 | +{"brokenlink","flowerpower.net","purchasedomain.com"} |
| 81 | + |
| 82 | +{"broken","rose tulips","cheap free domain biggest greatest"} |
| 83 | + |
| 84 | +{"biggest","enemy","hideout"} |
| 85 | + |
| 86 | +2 |
| 87 | + |
| 88 | +Returns: { } |
| 89 | + |
| 90 | +No website is dangerous and an empty String[] should be returned. |
| 91 | +2) |
| 92 | + |
| 93 | + |
| 94 | +{"a..a.ab.","...aa.b"} |
| 95 | + |
| 96 | +{"a bc def","def ghij klmno"} |
| 97 | + |
| 98 | +{"a","b","c","d","e"} |
| 99 | + |
| 100 | +1 |
| 101 | + |
| 102 | +Returns: {"a..a.ab.", "...aa.b" } |
| 103 | + |
| 104 | +3) |
| 105 | + |
| 106 | + |
| 107 | +{"www.tsa.gov"} |
| 108 | + |
| 109 | +{"information assurance signal intelligence research"} |
| 110 | + |
| 111 | +{"signal","assurance","penguin"} |
| 112 | + |
| 113 | +2 |
| 114 | + |
| 115 | +Returns: {"www.tsa.gov" } |
0 commit comments