Given a string htmlCode which is HTML code of a webpage, the task is to find the missing end tag in the HTML code.
Input: htmlCode = "<!DOCTYPE html> <html> <head> <title> GeeksforGeeks </title> </head> <body> <button> </body> </html>" Output: </button> Input: htmlCode = "<!DOCTYPE html> <html> <body> <p>Hello</p> </html>" Output: </body>
Approach: The idea is to use stack to keep track of the current start tags in the HTML Code and if at any moment there is an end tag which doesn’t match to the top of the stack which denotes a start tag. Then the tag which is at the top of the stack is to be closed first. Therefore, top of the stack will be the desired missing tag in the HTML Code.
Below is the implementation of the above approach:
- Convert the given RGB color code to Hex color code
- Find strings that end with a given suffix
- How to validate HTML tag using Regular Expression
- Count strings that end with the given pattern
- Program to build a DFA to accept strings that start and end with same character
- How to validate pin code of India using Regular Expression
- How to validate Hexadecimal Color Code using Regular Expression
- How to validate IFSC Code using Regular Expression
- Find maximum of minimum for every window size in a given array
- Find all occurrences of a given word in a matrix
- Find all the patterns of "1(0+)1" in a given string | SET 1(General Approach)
- Find all the patterns of "1(0+)1" in a given string | SET 2(Regular Expression Approach)
- Iterative method to find ancestors of a given binary tree
- Find the element at R'th row and C'th column in given a 2D pattern
- Find index of closing bracket for a given opening bracket in an expression
- Find minimum length sub-array which has given sub-sequence in it
- Find the product of last N nodes of the given Linked List
- Find the element in the matrix generated by given rules
- Find if a binary matrix exists with given row and column sums
- Find the final number obtained after performing the given operation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.