FastPrepHTML Elements Single-Tag Correction
Problems/HTML Elements Single-Tag Correction

HTML Elements Single-Tag Correction

Odoo logoOdoo● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Odoo online assessment for a full-time role. The report leaves out a limit on the input length. We added one.

Our version is about 99% the same as the reported question.

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.

More Odoo interview questions

  • Compare Character Arrays with BackspacesOA · Seen Sep 2024
  • Employees Joined per MonthOA · Seen Sep 2024
  • Evaluate a Python Integer ExpressionOA · Seen Sep 2024
  • Maximum Profit from an Increasing Price TripletOA · Seen Jan 2023
  • Same Binary TreePHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Decode StringAbridge · OAAbridge interview questions
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Minimum Remaining LengthWells Fargo · OA · PHONE SCREENWells Fargo interview questions
  • Modify the StringYahoo · OAYahoo interview questions
  • Maximum Score in Balanced String 🍇Amazon · OA
  • Lexicographically Minimum Stack EncryptionRippling · OARippling interview questions
  • Shortest String After Erasing Equal PairsMarshall Wace · OAMarshall Wace interview questions
  • Create New VersionCisco · OACisco interview questions
All Odoo interview questionsSee Odoo hiring insights
Saved
class Solution {
    public String htmlElements(String str) {
      // Write your code here.
    }
}
Checking account…