duc178
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
def prefix_to_postfix(s)
operators = "+-*/"
a = s.split("")
i = a.size - 3
while i >= 0 do
if operators.include?(a[i])
a[i] = a[i+1] + a[i+2] + a[i]
a.delete_at(i+1)
a.delete_at(i+1)
end
i -= 1
end
a.join
end
puts prefix_to_postfix("-*+ABC*-DE+FG")
=> AB+C*DE-FG+*-
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
There will be no O(nlogn) solution using O(1) space. Recursion does uses extra space, it's not O(1).
- duc178 November 14, 2017If we can solve this O(nlogn) and O(1) space, we can easily convert the result to sorted array in-place in O(n), that means we can sort an array in O(nlogn) using O(1), which is not true.