Back to course home
0% completed
Vote For New Content
Could I not push each element to a hashmap and then just concat it?{ 0: [0,0], ...
Eduardo Sánchez
Apr 5, 2022
Could I not push each element to a hashmap and then just concat it?
{ 0: [0,0], 1: [1,1], 2: [2] } then I just concat those 3 arrays (still treating each of the numbers as an object. This will also be O(n) for time and space O(n)
1
0
Comments
Comments
Design Gurus4 years ago
Yes, that would work too. Although, the solution we presented runs in constant space O(1).
D
dg 3 years ago
The Solution heading could be explained a bit better here. Without looking at the code, it looks like the point is that you iterate low and high inward on each tick.
On this page
Problem Statement
Examples
Example 2
Try it yourself