FastPrepRender Sidebar Labels as HTML

Render Sidebar Labels as HTML

Klaviyo logoKlaviyo● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

For this exercise, render the supplied ordered text labels as one sidebar HTML string.

  1. Begin with exactly <aside><ul>.
  2. For every label in input order, append <li>, the escaped label, and </li>.
  3. End with exactly </ul></aside>.

Inside each label, replace & with &amp;, < with &lt;, and > with &gt;. Copy every other character unchanged, including quotes and spaces. Interpret the input as literal text, so entity-looking strings are escaped too.

  • Preserve item order, duplicate labels and empty labels.
  • An empty input list produces only the outer wrapper.
  • Add no extra whitespace, attributes, links, styling or routing behavior.

The source did not supply original markup, item data or a repository. This callable renderer is the explicit practice representation of the reported sidebar-rendering task.

Function

renderSidebar(labels: String[]) → String

Examples

Example 1

labels = ["One","Two"]return = "<aside><ul><li>One</li><li>Two</li></ul></aside>"

Each label becomes one list item in the same order.

Example 2

labels = ["A&B","<tag>"]return = "<aside><ul><li>A&amp;B</li><li>&lt;tag&gt;</li></ul></aside>"

Ampersands and angle brackets in labels become text-node entities; only the fixed wrapper creates markup.

Constraints

  • 0 <= labels.length <= 1000.
  • Every label contains only printable ASCII characters with codes from 32 through 126; empty labels are allowed.
  • The sum of all label lengths is at most 1000.

More Klaviyo problems

See Klaviyo hiring insights
public String renderSidebar(String[] labels) {
    // Write your code here
}
labels["One","Two"]
expected"<aside><ul><li>One</li><li>Two</li></ul></aside>"
Checking account…