Optimising a Solution
Optimising a solution: finding the step that dominates a solution's cost and removing it with a standard move, and knowing when to stop.
Optimising a solution is a procedure for making a correct but slow answer fast: cost each step, find the one that sets the total, compare it with the fastest any solution could be, and remove that step's waste with a standard move, saying what memory the move costs. It matters because a first answer in an interview is usually correct and too slow, and speeding up the wrong line, or carrying on past the point where no answer could be faster, spends the time without improving the answer. The topic opens on the six steps applied to a list of order numbers, then takes the best run of a market stall's trading days from O(n³) to one pass, and shows the before and the after in Python, Java and TypeScript. It weighs what three faster ways to find the most common reading cost in memory, stops at the fastest possible answer for the guests who came both years, shows a fix that makes the wrong step faster, and ends with an exercise on the longest run of raffle tickets.
Contents
8 cardsnot started