Figma logo

Figma

San Francisco, CADesign

Interview Questions

Keyword Highlighting System

Asked at Figma
technical
string manipulation
algorithms

Implement a function to highlight keywords in text.

Function Signature:

function highlight(keyword: string, text: string): string;

Part 1: Basic Implementation Example:

Input: keyword = "fig", text = "figma"
Output: "<b>fig</b>ma"

Part 2: Overlapping Matches Example:

Input: keyword = "ana", text = "banana"
Output: "b<b>anana</b>"
Note: NOT "b<b>ana</b>na" - maximize coverage

Part 3: Multiple Keywords

  • Handle multiple keywords efficiently
  • Maintain maximum coverage
  • Resolve overlapping matches

Share Your Experience at Figma