For the best experience, increase the window size or view on a laptop or desktop device
Last updated: Pending
Title | ||
|---|---|---|
Loading... | ||
1/1
No questions are available yet
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
Given a keyword and a string, bold all occurrences of the keyword by wrapping them in <b> tags.
Part 1:
function highlight(keyword: string, text: string): string;
// Example 1:
Input: keyword = "fig", text = "figma"
Output: "<b>fig</b>ma"
Followup 1:
If there are overlapping matches, the bold tags should cover the maximum possible characters.
// Example 2:
Input: keyword = "ana", text = "banana"
Output: "b<b>anana</b>"
// NOT "b<b>ana</b>na" - we want to bold the maximum coverage
Followup 2:
How would you handle multiple keywords?
Given a keyword and a string, bold all occurrences of the keyword by wrapping them in <b> tags.
Part 1:
function highlight(keyword: string, text: string): string;
// Example 1:
Input: keyword = "fig", text = "figma"
Output: "<b>fig</b>ma"
Followup 1:
If there are overlapping matches, the bold tags should cover the maximum possible characters.
// Example 2:
Input: keyword = "ana", text = "banana"
Output: "b<b>anana</b>"
// NOT "b<b>ana</b>na" - we want to bold the maximum coverage
Followup 2:
How would you handle multiple keywords?
Output