This problem is just an implementation detail and does not require any algorithmic thinking whatsoever. But there’s a peculiarity in it regarding how regex works.
So, the separator that they provide is a special character and regex has special rules for special characters. If you want to match the special characters ($, %, ^, &, #, @, !, *, period
), you have to prefix your regex string with \\Q
and suffix it with \\E
.
Code:
Java
Big O Analysis
-
Runtime
The runtime complexity here is
O(N*K)
, where K is length of the largest word in the array. -
Memory
The memory usage is
O(1)
since we don’t use any extra datastructure.
— A