Reported September 2023
Odoostack

HTML Elements Single-Tag Correction

Reported by candidates from Odoo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Odoo OA. Under 2s to a working solution.
Founder's read

Odoo reportedly served this one in September 2023, and the catch is in the return value, not the nesting check. You're not just validating tags. You have to name the earliest tag token whose rename fixes the whole string. It looks like a stack problem you've seen a hundred times, then the edge cases show up. If you blank during the live OA, StealthCoder runs invisibly on your desktop and can hand you a working approach. Better to understand the trick first, so read on.

The problem

Given a string str containing plain text and HTML-like tags, determine whether its tags are properly nested. The only tag names used are b, i, em, div, and p.
A string is properly nested when every closing tag matches the most recently opened tag that has not yet been closed.
If str is properly nested, return the string true. Otherwise, exactly one tag name can be changed to a different allowed tag name to make the string properly nested. The tag remains opening or closing after the change. Return the original name of the earliest tag token whose name can be changed to make the whole string properly nested.

Function
htmlElements(str: String) → String

Examples
Example 1
str = "<div><b><p>hello world</p></b></div>"
return = "true"
Each closing tag matches the most recently opened tag, so the string is already properly nested.
Example 2
str = "<div><i>hello</i>world</b>"
return = "div"
Changing the first <div> tag to <b> makes the string properly nested, so return its original name, div.
Example 3
str = "<div><div><b></b></div></p>"
return = "div"
Changing the first <div> tag to <p> makes all tags match. Although changing the final closing tag also works, the first tag occurs earlier.
Example 4
str = "<div>abc</div><p><em><i>test test test</b></em></p>"
return = "i"
Changing <i> to <b> makes the second top-level element properly nested.

Constraints
Every tag name is one of b, i, em, div, or p.
If str is not already properly nested, changing exactly one tag name can make it properly nested.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Parse the tags with a regex or manual scan, keeping opening and closing as separate token types. Run a standard stack. On the first mismatch, a closing tag meets a different opener on top of the stack. That's your conflict, but the culprit isn't always the closing tag. Example 3 proves it: renaming the earlier opening div works, and the earliest valid token wins. So at the mismatch you have two candidates, the stack top's opener or the closer, and the answer is the opener's original name since it appears earlier. Pitfall: the opener you blame may not be the top. Verify by simulating the rename, or test each candidate token in order against a full check. Since the constraints guarantee one rename fixes it, brute force over tokens and 4 alternative names is fine for small inputs. If you freeze mid-OA, StealthCoder is the hedge, but the mismatch logic is only about ten lines.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill HTML Elements Single-Tag Correction cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Odoo's OA.

Odoo reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

HTML Elements Single-Tag Correction FAQ

What's the trick in the Odoo HTML Elements problem?+

It's a bracket-matching stack, but the answer is the earliest tag whose rename fixes everything. At the first mismatch, the opener on the stack top is usually earlier than the closer, so you report the opener's name. Don't just return the closer that failed.

How hard is this really?+

Medium. The stack part is easy. The difficulty is deciding which token to blame and handling cases where the stack is empty or has leftovers. If you can write valid parentheses cleanly, you're most of the way there.

Can I just brute force the rename?+

Yes. For each tag token in order, try each of the other four allowed names, run a full nesting check, and return the first token that passes. It's O(n squared) at worst, which is fine when you want correctness first and can optimize after.

What edge cases should I test?+

Test an already valid string returning true, a mismatch where the opener is the culprit like Example 3, one where the closer is the only fix, and plain text between tags. Also check nested same-name tags, since div inside div can hide the bug.

How do I prepare in 48 hours for this Odoo OA?+

Write valid parentheses from memory, then extend it to tags with a tokenizer. Practice returning the position or name of the first failure instead of a boolean. Then run Examples 2 to 4 by hand. That covers this problem and its close variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Odoo.

OA at Odoo?
Invisible during screen share
Get it