We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Detect the Domain Name
Detect the Domain Name
CalvinWestwood + 0 comments Your expected output contains domain names not present in the input HTML code
wthit56 + 0 comments This is way too difficult without any spec on what constitutes a domain. It seems the expected output uses hidden rules for figuring out if a domain is "legal" or not.
jackbanh + 0 comments This question needs a bit more polish. The instructions and test cases could use more clarity.
- "www." and "ww2." are expected to be filtered out but this instruction is easy to miss.
- In the real world, you cannot assume that "www.example.org" and "example.org" resolve to the same place
- The test case inputs are truncated so it's harder to debug
- There is no hint for which special characters are valid in a domain name
jobe_tr + 0 comments Sigh. I spent far too long before realzing that the regex includes "http" or "https" in their regex.
In normal html this is a valid link
<a href="//google.com">Google.com</a>
I was pulling those domains with my regex, but the solution does not.
mai_the_09 + 0 comments Java 8 Solution
public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine().trim()); Pattern pa = Pattern.compile("http[s]?:\\/\\/(ww[w2]\\.)?(([a-zA-Z0-9\\-]+\\.)+([a-zA-Z\\-])+)"); TreeSet<String> set = new TreeSet<>(); while (n-- > 0) { String input = in.nextLine(); Matcher ma = pa.matcher(input); while (ma.find()) set.add(ma.group(2)); } for (String str : set) { System.out.print((str != set.last()) ? str + ";" : str); } } }
Load more conversations
Sort 113 Discussions, By:
Please Login in order to post a comment