Update appNew update is available. Click here to update.
About
Bangalore Institute of Technology 2024
C++ - Default language
My Stats
EXP gained
yellow-spark
1211
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
0
Know more
21
Total problems solved
19
Easy
2
Moderate
0
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

3 days

Less

More

Achievements
1
Ronin
Topics
Arrays
Discussions
tc 10/11
Interview problems

int bestTimeToBuyAndSellStock(vector<int>&prices) {    // Write your code here.    int n=prices.size();    int b;    int min_price=INT_MAX;    int max_price=INT_MIN;

   for(int i=0;i<n-1;i++){        if(prices[i]<=min_price)min_price=prices[i];    }

   for(int i=0;i<n;i++){        if(prices[i]==min_price)b=i;    }

   for(int j=b;j<n;j++){        if(prices[j]>max_price)max_price=prices[j];    }

   return max_price-min_price; }  

profile
Aryaman Singh
Published On 28-Oct-2023
35 views
0 replies
0 upvotes