FastPrepRender Sidebar Labels as HTML
Problems/Render Sidebar Labels as HTML

Render Sidebar Labels as HTML

Klaviyo logoKlaviyo● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Klaviyo onsite interview. The report only says the task is rendering a sidebar. We chose the ordered labels, a function that returns HTML, the exact markup and how text is escaped. Our version is about 40% the same as the reported question. The report gives Klaviyo as the employer, even though its title mentions Coinbase.

For this exercise, you are given a list of text labels in order. Build the HTML for a sidebar that shows them, and return it as one string.

  1. Start with exactly <aside><ul>.
  2. For each label, in the order given, add <li>, then the escaped label, then </li>.
  3. Finish with exactly </ul></aside>.

To escape a label, replace & with &amp;, < with &lt;, and > with &gt;. Keep every other character as it is, including quotes and spaces. Treat each label as plain text, so text that already looks like an HTML entity is escaped too.

  • Keep the labels in order, and keep duplicate labels and empty labels.
  • If the list is empty, return only the outer wrapper.
  • Do not add extra whitespace, attributes, links, styling or routing behavior.

Function

renderSidebar(labels: String[]) → String

Examples

Example 1

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

The output opens the wrapper, turns One and Two into one list item each, in that order, and then closes the wrapper.

Example 2

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

In the first label A&B, the ampersand becomes &amp;. In the second label, the angle brackets become &lt; and &gt;, so the tag shows as text instead of real markup. Only the fixed wrapper adds real HTML tags.

Constraints

  • 0 <= labels.length <= 1000.
  • Every label uses only printable ASCII characters, with codes from 32 through 126. Labels may be empty.
  • The sum of all label lengths is at most 1000.
See Klaviyo hiring insights
Saved
class Solution {
    public String renderSidebar(String[] labels) {
        // Write your code here
    }

}
Checking account…