전체 글 359

[LeetCode] 11 Container With Most Water

Question: You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Example 1: Inp..

How to Optimize Solutions for Coding Problems

Example: Print all positive integer solutions to the equation a^3 + b^3 = c^3 + d^3 and a, b, c, d are integers between 1 and 1000. 1. A brute force solutions n = 1000 n = 1000 for a from 1 to n for b from 1 to n for c from 1 to n for d from 1 to n if a^3 + b^3 = c^3 + d^3 print a, b, c, d This returns O(n^4) To optimize it we can make a break when we find it n = 1000 for a from 1 to n for b fro..