Pregunta de entrevista

Entrevista de Frontend Engineer

-

Meta

Round 1: Given a string and a style array render HTML pretty much like a rich text editor. For example: 'Hello, world', [[0, 2, 'i'], [4, 9, 'b'], [7, 10, 'u']] Output: '<i>Hel</i>l<b>o, w<u>orl</u></b><u>d</u> something like that.

Respuesta

Respuestas de entrevistas

3 respuestas

1

I used a hash map and a stack to store the indices. I pushed the style into a stack and popped off when I hit the index. I had to write the output so I took care of not having invalid HTML having the <b> and <u> mixed up. This particular use case I had to take care. The interviewer gave me some hints around the hash map but I came up with the algorithm and implemented almost through the complete hour.</u></b>

Anónimo en

0

You can answer it as an algorithm question. Or you can answer it like a true FEE by leveraging the platform. 1. Flatten the tags into a single array of open and close tag pairs. 2. Sort the flattened tags by injection index. 3. Insert tags in reverse order to preserve shifting index. 4. Join the string and pass it to innerHTML and let the browser handle the rest

Anónimo en

0

Hey! I am trying to solve this problem. Can you give me some direction?

Anónimo en

Añadir respuestas o comentarios

Para publicar un comentario sobre esto, inicia sesión o regístrate.