Professional Documents
Culture Documents
AP exp 3.3.pdfyug
AP exp 3.3.pdfyug
1. Aim:
To Solve the Best time to buy and sell the stock
To Solve the longest Palindromic substring
2. Objective:
You are given an array prices where prices[i] is the price of a given stock
on the ith day.You want to maximize your profit by choosing a single day to
buy one stock and choosing a different day in the future to sell that stock.
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.empty()){
return 0;
}
int maxprice=0;
int minprice=prices[0];
for(int i=1;i<prices.size();i++){
if(prices[i]<minprice){
minprice=prices[i];
}
else{
int currprofit=prices[i]-minprice;
maxprice=max(maxprice,currprofit);
class Solution {
public:
std::string longestPalindrome(std::string s) {
if (s.length() <= 1) {
return s;
}
return max_str;
}
};