🚀 CheckDOM - HTML Element - coderbyte / Odoo Coding Challenge
Have the function CheckDOM(strParam)
read the strParam
parameter being passed which will be a string of HTML elements and plain text.
The elements that will be used are: <b>
, <i>
, <em>
, <div>
, <p>
.
Your program should support 3 cases:
- the string is a correct sequence of nested HTML elements, it should return
true
- the string is almost correct: by changing a single tag you can make it correct, it should return the first tag to change. Changing a tag does not include adding or removing a tag, or changing the opening into a closing tag and vice versa.
- the string is incorrect (and to be correct it would require changing more than one element), your program should return
false
.
Input: "<div><b><p>hello world</p></b></div>"
Output: true
Reason: the HTML is nested correctly
Input: "<div><i>hello</i>world</b>"
Output: "div"
Reason: if the first `<div>` element were changed into a `<b>`, the string would be properly nested
Input: "</div><p></p><div>"
Output: false
Reason: the order of opening and closing tags is not respected, changing any one tag cannot make it correct
Input: "<em></em><em></em><p></b>"
Output: p
Input: "< div>< p></p>< b><p></div>"
Output: false
Search for any help or documentation you might need for this problem. For example: array indexing, Ruby hash tables, etc.
graph TD;
A[Start] --> B{Is the string correctly nested? + sequence order};
B -- Yes --> C[Return true];
B -- No --> D{Can it be corrected by changing one tag? no adding or removing};
D -- Yes --> E[Return the first tag to change];
D -- No --> F[Return false];
If you find this project helpful, please consider giving it a star ⭐ on GitHub!
This project is licensed under the MIT License - see the LICENSE file for details.
Keywords: odoo coding challenge, Odoo developer position, odoo coding test, Odoo assessment, odoo coderbyte, odoo technical assessment, odoo belgium, odoo europe, odoo india