"Idea for solution:
Reverse the complete char array
Reverse the words separated by space. i.e. Find the space characters and the reverse the subarray between two space characters.
vector reverseSubarray(vector& arr, int s, int e)
{
while (s reverseWords(vector& arr )
{
int n = arr.size();
reverse(arr, 0, n - 1"
Rahul M. - "Idea for solution:
Reverse the complete char array
Reverse the words separated by space. i.e. Find the space characters and the reverse the subarray between two space characters.
vector reverseSubarray(vector& arr, int s, int e)
{
while (s reverseWords(vector& arr )
{
int n = arr.size();
reverse(arr, 0, n - 1"See full answer
"def traprainwater(height: List[int]) -> int:
n = len(height)
totalwaterlevel = 0
for i in range(n):
j = i+1
while j = n:
break
rows = j - i -1
intrwaterlevel = min(height[j], height[i]) * rows
for k in range(i+1, j):
intrwaterlevel -= height[k]
totalwaterlevel += intrwaterlevel
i = j
return totalwaterlevel"
Manoj R. - "def traprainwater(height: List[int]) -> int:
n = len(height)
totalwaterlevel = 0
for i in range(n):
j = i+1
while j = n:
break
rows = j - i -1
intrwaterlevel = min(height[j], height[i]) * rows
for k in range(i+1, j):
intrwaterlevel -= height[k]
totalwaterlevel += intrwaterlevel
i = j
return totalwaterlevel"See full answer
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.