Revised some previous problems with some better solutions in terms of time/space complexity. Some more detailed explanations were commented as well.