Skip to content

Instantly share code, notes, and snippets.

@Elviselly2
Last active April 30, 2025 21:30
Show Gist options
  • Save Elviselly2/90d9a1d8874e601f60a7ea6dda2e7163 to your computer and use it in GitHub Desktop.
Save Elviselly2/90d9a1d8874e601f60a7ea6dda2e7163 to your computer and use it in GitHub Desktop.
Pseudocode
BEGIN
FUNCTION HTMLElements(str)
DEFINE validTags AS ["b", "i", "em", "div", "p"]
CREATE an empty stack
FOR each character in str
IF it is an opening tag THEN
PUSH it onto the stack
ELSE IF it is a closing tag THEN
IF stack is empty THEN
RETURN the mismatched closing tag
ELSE
POP top element from the stack
IF popped element does not match current closing tag THEN
RETURN the mismatched opening tag
END IFs
IF stack is empty THEN
RETURN "true"
ELSE
RETURN the first unmatched opening tag
END FUNCTION
END
@Elviselly2
Copy link
Author

this is my gist on stuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment