HackerRank Regex Challenge: Detect HTML Tags
Naming/Style


public class Detect_HTML_Tags {



Usually classes get noun names, like HTML_Tag_Lister.  


        int N = Integer.parseInt(br.readLine().trim());



It's more common in Java for all upper case variables to be constants:  

        final int N = Integer.parseInt(br.readLine().trim());


Note that you can assign constants at runtime in Java.  


        for(int i=0;i&lt;N;i++)
        {



Most places you put the { on the same line as the command.  Here you put it on the next line.  While both are valid, it's generally easier to read the code if you pick one style or the other.  There are some exceptional cases, but this isn't one of them.  

        for (int i = 0; i &lt; N; i++) {


As I went through your code, I added additional spaces for readability.  

Favor interfaces over implementations


        TreeSet&lt;String&gt; tree=count_html_tags(s);



A TreeSet is a specific implementation.  As a general rule, you want variable types to be interfaces.  This allows you to switch the implementation without changing the variable type in multiple places.  You could make the type a NavigableSet, but it should be sufficient to make it a SortedSet.  It might even be enough to make it a Set or Collection with the current code.  So something like 

        SortedSet&lt;String&gt; tags = find_html_tags(s);


Note that you don't count the HTML tags.  You find and return them.  

Also, I find tags to be a more descriptive name than tree or set.  

Later 


    private static TreeSet&lt;String&gt; count_html_tags(String s) {



changes to 

    private static SortedSet&lt;String&gt; count_html_tags(String s) {


Keep it simple if you can

In the following 


        String s1="";
        for(String t:tree){
            s1=t;
            if(i==tree.size()-1)
                break;
            System.out.print(t+";");
            i++;
        }



You could change to 

        if (tags.empty()) {
            return;
        }

        String last = tags.last();
        tags.remove(last);
        for (String tag : tags) {
            System.out.print(tag + ";");
        }
        System.out.println(last);


This avoids the i variable and updating the s1 variable on every iteration of the loop.  You also don't have to check on every iteration of the loop in order to end it exactly one iteration early.  

Note that last is a method on SortedSet.  As best I can tell, this is the only reason why tags can't be a simple Collection in main.  

Bugs?

The problem statement suggests that &lt; p /&gt; is a valid tag, but your regular expression won't match it because of the space between the &lt; and the p.  

The problem statement also suggests that &lt;p&gt; is only a valid tag if it has a matching &lt;/p&gt;, but you never check for that.  Perhaps that's not actually necessary.  The problem statement says what is valid but doesn't mention you enforcing it.