The ups and downs of the major indexes over the last three years has been a frustrating experience for new investors. But history shows that the strongest companies always bounce back, providing investors a chance to buy top stocks before they take off again.

Over the last century, there have been several bear markets, but even if you could have invested $100 in the S&P 500 index (going by the Composite Index back then) in 1927 -- right before the biggest market crash in history -- you would have over $1.1 million today.

Patiently holding shares of the best companies in the world is the easiest path to riches in the stock market. The following stocks are examples of the types of companies you want to think about buying right now, as well as the ones that you want to avoid.  

Buy Amazon: It has clear opportunities to generate profitable growth

One surefire buy for the next bull market is Amazon (AMZN -0.68%). The stock was halved in 2022 along with many other growth tech stocks. Investors were concerned about Amazon's slowing sales growth, which doesn't reflect the company's long-term potential. Even after partially rebounding this year, there are a few reasons investors shouldn't hesitate to add shares to their investment portfolio.

Amazon reported sales growth of just 9% last year, which was well off its previous 10-year annualized average of almost 24%. With over $514 billion in annual sales, Amazon is more exposed to the swings in consumer confidence than it used to be. 

Those headwinds will turn to tailwinds. The last three years have been anything but normal for the broader economy and Amazon, but the company may not be getting enough credit for still reporting higher sales despite tremendous disruptions to retailers.

AMZN Revenue (Quarterly) Chart

Data by YCharts

Amazon has already shown some progress as headwinds in the economy start to recede. After a 1% decline in online store sales at the start of 2022, growth accelerated over the last year with sales up 5% year over year in the most recent quarter. 

Even Amazon's physical stores have been growing faster than its online business, which suggests the online business is capable of growing faster, considering the long-term tailwinds fueling e-commerce. Amazon's focus on improving inventory management and speeding up logistics will lead to faster delivery, more satisfied customers, and better profit performance as the broader e-commerce market recovers.

Investors should also pay attention to Amazon Web Services (AWS), the company's cloud computing arm that makes up 17% of Amazon's total sales. AWS has been one of the company's faster-growing businesses in recent years but saw growth slow last year as organizations tightened their budgets in an uncertain economy. However, AWS could see accelerating growth in the years to come as it serves the growing demand for generative artificial intelligence (AI), where Amazon could become a major player in helping companies gain better insight and productivity from their data using this technology.

Since AWS generates revenue based on the resources customers use, the growing use of AI services could be very lucrative. Amazon's operating profit more than doubled year over year last quarter to over $7.6 billion, with AWS contributing $5.3 billion of the total. This is why growth at AWS is a major catalyst for the stock, as it is still the main engine of Amazon's profitability.

The stock is trading 25% off its previous highs but profitable growth from online stores and AWS should push the stock to new highs over the next decade.  

Avoid Peloton: Falling sales with uncertain long-term growth

Amazon has clear opportunities to deliver more returns to investors, but the same cannot be said for fitness service provider Peloton Interactive (PTON 9.98%).

A lot has changed over the last three years for this once fast-growing maker of exercise bikes. Quarterly sales are down nearly 40% since the December-ending quarter of 2020. As demand fell off following the rush to buy at-home exercise equipment during the pandemic, the company was left with too many unsold bikes sitting in warehouses. That has contributed to the company's net loss of $1.26 billion over the last four quarters. 

New CEO Barry McCarthy has made progress in turning the company's finances around. The company's net loss has narrowed from over $1.2 billion a year ago to $242 million in the June-ending quarter, but the overarching problem for investors is uncertainty about long-term demand.

Demand for connected fitness products is more concerning after the most recent quarter, where Peloton reported a 2% decline in memberships over the previous quarter and 5% year over year. Sales of connected fitness products fell 32% over the previous quarter and don't seem even close to stabilizing.

By comparison, leading gym operator Planet Fitness has reported solid growth over the last few years. The popular fitness chain is proving to be more resilient to choppy consumer spending than Peloton, and the same can be said for Amazon, given its improving sales growth over the last year.

Overall, it's difficult to tell if Peloton is suffering from the high inflation impacting many retailers right now, or if there has been a permanent shift in consumer preference for other workout types, such as strength training, which is trending at the expense of online training. 

With a lack of clarity about Peloton's future, I would avoid the temptation to buy the stock at these low share prices, and instead, stick with a proven long-term winner like Amazon.