Uncompress Flashcards

1
Q

What’s the problem about?

A

<number><char> pattern where you will need to repeat the number of char
- sometimes number can be multiple digits
</char></number>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What variables or data structures will you use?

A
  • Store result in array instead of concat strings because concat is O(n)
  • Create pointer variables start and end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is your approach?

A
  • Create a while loop to run as long as end is less than length of s
  • check if index value based on end pointer is a number
    • if it is, then increment end pointer
    • if not, slice s to get the num using start and end pointer
    • convert num from string to number
    • loop over num and push string to result array
  • increment end pointer
  • assign start pointer to end pointer
  • return result with join(‘’) method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the time complexity?

A

O(n*m)
n = # of groups(number with char)
m = max number for any group(like if we had 1000)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is space complexity?

A

O(n*m)
- we have to construct that output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly