De Shaw SDE Interview question

Revision en3, by peroooo, 2021-04-02 13:07:11

Question: Given an encoded String eg "a2bb3k11" that can be expended after decode "aabbbbbbkkkkkkkkkkk" and you have performe given range queries and find the length of the expended string;

input : a2bb3k11
3
0,3 = "a2bb"
2,5 = "bb3k"
2,6 = "bb3k1"
output: 2 = "aa"
6 = "bbbbbb"
7 = "bbbbbbk"

brute force will give (n*q) or (n^2) solution is there any way to optimize the queries to log(n) time.

Tags #help, #range query, #advance data structures

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English peroooo 2021-04-02 13:07:11 4 Tiny change: '\noutput: 4 = "aabb" ' -> '\noutput: 2 = "aa" '
en2 English peroooo 2021-04-02 12:27:08 901
en1 English peroooo 2021-04-02 12:20:49 488 Initial revision (published)