leetcode like problem? optimization of nesting tags
i made a program to make text look spooky in html
which is achieved by randomly applying a style tag to every single character
however, the problem is that it really quickly balloons in character count and that's a problem for me


3 Replies
⌛
This post has been reserved for your question.
Hey @2ndchar! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
i've asked for help with this problem elsewhere, and someone made the observation that i can manually cut down on the tags by deleting any tags that match the pattern of </??><??>
it seems to me that i need to save the previous character's tags first
and then check the current tags against the first one and print accordingly
for example
(to cut down on complexity, pretend the numbers represent tags like <b>, and the numbers just represent their correct order)
if the previous character's tags was 1 2 3 4 5
and the current character's tag was 1 2 3
so, unoptimized, it would look like
1 2 3 4 5
(A)
5 4 3 2 1 1 2 3 (B)
3 2 1
optimized, it would look like
1 2 3 4 5 (A)
5 4 (B)
3 2 1
one approach i haven't tried yet is looking at this problem literally step by step
at (A)
, the program knows it has tags 1 2 3 4 5
since it's at the beginning, it prints all of 1 2 3 4 5
then it looks at the next letter, (B)
, and its tags are 1 2 3
i see that 4 and 5 is missing, so i print out 5 and 4
and then i look at the next letter and see that there's none
so i print out 3 2 1💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.