https://github.com/maikelsouza/tagcontentextractor
HackerRank Home Website Tag Content Extractor Test Solution
https://github.com/maikelsouza/tagcontentextractor
java-11 junit5
Last synced: 5 months ago
JSON representation
HackerRank Home Website Tag Content Extractor Test Solution
- Host: GitHub
- URL: https://github.com/maikelsouza/tagcontentextractor
- Owner: maikelsouza
- Created: 2024-12-10T11:04:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-13T11:25:25.000Z (over 1 year ago)
- Last Synced: 2025-09-21T06:47:15.387Z (10 months ago)
- Topics: java-11, junit5
- Language: Java
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tag-Based Language Parser
In a tag-based language like XML or HTML, contents are enclosed between a start tag and an end tag like `contents`. Note that the corresponding end tag starts with a `/`.
Given a string of text in a tag-based language, parse this text and retrieve the contents enclosed within sequences of well-organized tags meeting the following criteria:
1. The name of the start and end tags must be the same. The HTML code `
Hello World` is not valid, because the text starts with an `h1` tag and ends with a non-matching `h2` tag.
2. Tags can be nested, but content between nested tags is considered not valid. For example, in `
contentsinvalid
`, `contents` is valid but `invalid` is not valid.
3. Tags can consist of any printable characters.
## Input Format
- The first line of input contains a single integer, `N` (the number of lines).
- The `N` subsequent lines each contain a line of text.
## Constraints
- \( 1 \leq N \leq 100 \)
- Each line contains a maximum of \( 10^4 \) printable characters.
- The total number of characters in all test cases will not exceed \( 10^6 \).
## Output Format
For each line, print the content enclosed within valid tags.
- If a line contains multiple instances of valid content, print out each instance of valid content on a new line.
- If no valid content is found, print `None`.
## Sample Input
```4```\
```
Nayeem loves counseling
```\
```Sanjay has no watch
So wait for a while```\
```safat codes like a ninja```\
```Imtiaz has a secret crush```
## Sample Output
```Nayeem loves counseling```\
```Sanjay has no watch```\
```So wait for a while```\
```None```\
```Imtiaz has a secret crush```
# Solution
### The solution is implemented in the Solution.java class
# Test
### You can run the test class SolutionTest.java