Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Code for Best Time To Buy and Sell Stocks and Added Different Error Page Templates #211

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "bits/stdc++.h"
using namespace std;

int solve(vector<int> &prices, int k)
{
int n = prices.size();
if (k >= n / 2)
{
int profit = 0;
for (int i = 1; i < n; i++)
if (prices[i] > prices[i - 1])
profit += prices[i] - prices[i - 1];
return profit;
}

vector<int> buy(k + 1, INT_MIN);
vector<int> sell(k + 1, 0);

int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 1; j <= k; j++)
{
buy[j] = max(buy[j], sell[j - 1] - prices[i]);
sell[j] = max(sell[j], buy[j] + prices[i]);
}
}

return sell[k];
}
19 changes: 19 additions & 0 deletions DSA/Cpp/Dynamic_Programming/Best Time to Buy and Sell Stocks I.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;

int maxProfit(const vector<int> &A)
{
int minVal = INT_MAX;
int maxProfit = 0;

for (int i = 0; i < A.size(); i++)
{
if (A[i] < minVal)
minVal = A[i];
else
{
maxProfit = max(maxProfit, A[i] - minVal);
}
}
return maxProfit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "bits/stdc++.h"
using namespace std;

int Solution::maxProfit(const vector<int> &A)
{
if (A.size() == 0)
return 0;
int min = A[0];
int sum = 0;
for (int i = 1; i < A.size(); i++)
{
if (A[i] < min)
{
min = A[i];
}
if (A[i] > min)
{
sum = sum + A[i] - min;
min = A[i];
}
}
return sum;
}
90 changes: 90 additions & 0 deletions WebDev/HTML-CSS/Error Page/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>400 | Bad request.</title>

<style type="text/css">
body {
padding: 30px 20px;
font-family: -apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
"Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
color: #727272;
line-height: 1.6;
}

.container {
max-width: 500px;
margin: 0 auto;
}

h1 {
margin: 0 0 40px;
font-size: 60px;
line-height: 1;
color: #252427;
font-weight: 700;
}

h2 {
margin: 100px 0 0;
font-size: 20px;
font-weight: 600;
letter-spacing: 0.1em;
color: #A299AC;
text-transform: uppercase;
}

p {
font-size: 16px;
margin: 1em 0;
}

.go-back a {
display: inline-block;
margin-top: 3em;
padding: 10px;
color: #1B1A1A;
font-weight: 700;
border: solid 2px #e7e7e7;
text-decoration: none;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 0.1em;
}

.go-back a:hover {
border-color: #1B1A1A;
}

@media screen and (min-width: 768px) {
body {
padding: 50px;
}
}

@media screen and (max-width: 480px) {
h1 {
font-size: 48px;
}
}
</style>
</head>
<body>

<div class="container">
<a href="https://placeholder.com" class="brand"><img src="http://via.placeholder.com/360x200?text=Your+Logo" width="180" height="100"></a>

<h2>400</h2>
<h1>Bad request.</h1>

<p>We’re sorry but something appears to be wrong with the request you made, please try again.</p>

<span class="go-back"><a href="/">Go back</a></span>
</div>

</body>
</html>
90 changes: 90 additions & 0 deletions WebDev/HTML-CSS/Error Page/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>404 | Page not found.</title>

<style type="text/css">
body {
padding: 30px 20px;
font-family: -apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
"Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
color: #727272;
line-height: 1.6;
}

.container {
max-width: 500px;
margin: 0 auto;
}

h1 {
margin: 0 0 40px;
font-size: 60px;
line-height: 1;
color: #252427;
font-weight: 700;
}

h2 {
margin: 100px 0 0;
font-size: 20px;
font-weight: 600;
letter-spacing: 0.1em;
color: #A299AC;
text-transform: uppercase;
}

p {
font-size: 16px;
margin: 1em 0;
}

.go-back a {
display: inline-block;
margin-top: 3em;
padding: 10px;
color: #1B1A1A;
font-weight: 700;
border: solid 2px #e7e7e7;
text-decoration: none;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 0.1em;
}

.go-back a:hover {
border-color: #1B1A1A;
}

@media screen and (min-width: 768px) {
body {
padding: 50px;
}
}

@media screen and (max-width: 480px) {
h1 {
font-size: 48px;
}
}
</style>
</head>
<body>

<div class="container">
<a href="https://placeholder.com" class="brand"><img src="http://via.placeholder.com/360x200?text=Your+Logo" width="180" height="100"></a>

<h2>404</h2>
<h1>Page not found.</h1>

<p>We’re sorry but it appears that we can’t find the page you were looking for. Usually this occurs because of a page that previously existed was removed or you’ve mistyped the address.</p>

<span class="go-back"><a href="/">Go back</a></span>
</div>

</body>
</html>
90 changes: 90 additions & 0 deletions WebDev/HTML-CSS/Error Page/422.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>422 | The change you wanted was rejected.</title>

<style type="text/css">
body {
padding: 30px 20px;
font-family: -apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
"Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
color: #727272;
line-height: 1.6;
}

.container {
max-width: 500px;
margin: 0 auto;
}

h1 {
margin: 0 0 40px;
font-size: 60px;
line-height: 1;
color: #252427;
font-weight: 700;
}

h2 {
margin: 100px 0 0;
font-size: 20px;
font-weight: 600;
letter-spacing: 0.1em;
color: #A299AC;
text-transform: uppercase;
}

p {
font-size: 16px;
margin: 1em 0;
}

.go-back a {
display: inline-block;
margin-top: 3em;
padding: 10px;
color: #1B1A1A;
font-weight: 700;
border: solid 2px #e7e7e7;
text-decoration: none;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 0.1em;
}

.go-back a:hover {
border-color: #1B1A1A;
}

@media screen and (min-width: 768px) {
body {
padding: 50px;
}
}

@media screen and (max-width: 480px) {
h1 {
font-size: 48px;
}
}
</style>
</head>
<body>

<div class="container">
<a href="https://placeholder.com" class="brand"><img src="http://via.placeholder.com/360x200?text=Your+Logo" width="180" height="100"></a>

<h2>422</h2>
<h1>The change you wanted was rejected.</h1>

<p>Maybe you tried to change something you didn't have access to.</p>

<span class="go-back"><a href="/">Go back</a></span>
</div>

</body>
</html>
Loading