Best Time to Buy and Sell Stock(LC-121)

Given an array prices where prices[i] is the price of a given stock on the ith day.

Find the maximum profit from buying and then selling a stock once, where you must buy before you sell. Return 0 if no profit is possible.

brute force:-

Initialize profit=0

simply do 2 nested loops

in the second one you go through the elements after the first one

if prices[j]>prices[i],we will see if the new profit is greater and if it is greater then we will update the profit

optimized:-

initialize profit=0

In this case we will keep track of the minPrice

And while iterating through the prices array, we will see that if the current price < minPrice then we will just update the minPrice

otherwise we will calculate the profit and if it is greater then we will update the profit

Longest Repeating Character Replacement(LC-424)

You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.

Return the length of the longest substring containing the same letter you can get after performing the above operations.