The stock market has kept investors on their toes over the last few years. At the midpoint of 2024, it's definitely been a robust period for the market.

The S&P 500 is trading up about 16% from January at the time of this writing. Bear in mind that the average annual stock market return is in the ballpark of 10%, as measured over nearly 100 years.

If you're looking for stocks to buy and hold for the long run, you should have a minimum investment horizon of three to five years and a strong thesis for the underlying businesses. On that note, here are two solid contenders to consider that look like no-brainer buys in 2024 and beyond.

1. Palantir

Palantir Technologies (PLTR 4.65%) is known for its various software platforms for big-data analytics used by private and public organizations around the world.

For corporate clients like Morgan Stanley and Merck and entities dealing with highly sensitive information, like the United States intelligence community and Department of Defense, Palantir has been a mainstay in digital infrastructure since its founding 20 years ago.

It doesn't store data. The company creates software platforms that enable clients to better process and review data in order to make decisions that drive more effective operations.

One example in a commercial context is the pharmaceutical company Merck, which has used software built by Palantir to assist with medical research and drug development as well as predictions for supply chains. Government clients use the software for highly secretive work and tracking their budgets.

Last year, Palantir launched its Artificial Intelligence Platform (AIP) to help with decision-making across a wide range of purposes. The fast adoption of AIP is driving strong revenue growth and profitability, as is the company's continued diversification of its revenue mix.

For many years, it relied almost entirely on government clients, and while these are still a large piece of the pie, growth in commercial clients has exploded.

In the first quarter of 2024, Palantir reported its sixth consecutive quarter of profitability according to generally accepted accounting principles (GAAP), totaling $106 million. Revenue rose 21% year over year to $634 million. Of that total, commercial revenue came to $299 million, a 27% year-over-year increase, while government revenue rose 16% year over year to $335 million.

Palantir's customer count increased 42% from the prior-year period. Management reports that businesses including a leading energy and infrastructure company in the U.S. and a multinational airline are relying on AIP for many uses. Lowe's Companies, which had not previously used AI, adopted the AIP platform to help over 1,000 customer service agents, subsequently reducing overdue tasks by 75%.

Investors seem to have a renewed interest in the stock, with shares trading up by more than 60% from a year ago at the time of this writing. The company's growing profitability and expanding customer base bode well, as does its continued expansion into the rapidly evolving world of AI. Long-term investors might want to get a slice of the action over the next five to 10 years.

2. Airbnb

Airbnb (ABNB 1.07%) is up around 10% year to date, and the company's impressive financial performance has underlined its resilience in a shifting spending environment. People are continuing to spend money on travel, even as many consumers' wallets are showing clear signs of strain.

The diverse uses for Airbnb's platform are driving growth. For example, the platform helps travelers looking for a boutique hotel stay or a full apartment in their favorite city, and those looking for long-term accommodations. The ability of people to live and work in places different than their actual place of residence for long periods of time is likely driving this growth.

Revenue in the first quarter of 2024 totaled $2.1 billion, an 18% hike from the same quarter in 2023. It was also the most profitable first quarter to date, with net income of $264 million.

The company continues to be a cash flow machine, generating just shy of $2 billion in cash from operations and the same amount of free cash flow (FCF) in 2023. Its trailing-12-month FCF margin amounted to 41%.

Growth in short-term bookings and home supply is outpacing long-term stays, but bookings of 28 days or more still account for a notable portion of the overall total. As of the first quarter, long-term stays accounted for 17% of gross nights booked.

Changes by Airbnb have made these stays more affordable, such as new payment options and discounts. Stays of three months or more were up 25% year over year in the first quarter. Active listings rose 17% year over year in the first quarter of 2024, a sign that interest by hosts and guests is driving rapid expansion.

Management wants to ensure that the platform offers what hosts and guests want. This includes adding new tools that make booking group trips easier plus more aggressive initiatives to remove low-quality listings.

Some investors might be put off by Airbnb's somewhat lofty price-to-earnings multiple of 19, but if you're a long-term investor looking for a quality travel stock with plenty of room left to soar, that price might be worth paying.