Skip to content

Instantly share code, notes, and snippets.

View shubham1710's full-sized avatar
🎯
Focusing

Kumar Shubham shubham1710

🎯
Focusing
View GitHub Profile
class Solution {
public:
int maxProfit(vector<int> &prices) {
int total = 0, sz = prices.size();
for (int i = 0; i < sz - 1; i++) {
if (prices[i+1] > prices[i]) total += prices[i+1] - prices[i];
}
return total;
}
};
@shubham1710
shubham1710 / Fkdk.cpp
Created December 28, 2019 15:15
Fdmdls
class Solution {
public:
int climbStairs(int n) {
int ways[n+1];
ways[0] = 1;
ways[1] = 1;
for (int i = 2; i <= n; i++) ways[i] = ways[i - 1] + ways[i - 2];
return ways[n];
}
};
@shubham1710
shubham1710 / Kk5t.cpp
Created December 29, 2019 12:26
Ffnfm
int Solution::hammingDistance(const vector<int> &A) {
int inputSize = A.size();
int mod = 1000000007;
int sum = 0;
for (int bitPosition = 0; bitPosition < 31; bitPosition++) {
int cntBitOne = 0, cntBitZero = 0;
for(int i = 0; i < inputSize; i++) {
if (A[i] & (1 << bitPosition)) cntBitOne++;
else cntBitZero++;
}
class Node:
def __init__(self, val):
self.right = None
self.data = val
self.left = None
def mirror(root):
if root.left is not None:
mirror(root.left)
if root.right is not None:
mirror(root.right)
#include<bits/stdc++.h>
using namespace std;
void printUnsorted(int arr[], int n)
{
int s = 0, e = n-1, i, max, min;
// step 1(a) of above algo
for (s = 0; s < n-1; s++)
{
if (arr[s] > arr[s+1])
break;
public int targetSum(int[] nums, int T) {
// Map: i -> sum -> value
Map<Integer, Map<Integer, Integer>> cache =
new HashMap<Integer,Map<Integer,Integer>>();
return targetSum(nums, T, 0, 0, cache);
}
// Overloaded recursive function
private int targetSum(
int[] nums, int T, int i, int sum,
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
//code
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();int n,m,i;
while(t-->0)
map< pair<int,int>, bool > visited;
for (int i = 0; i < n; i++) {
if (s[i] == 'N')
while (visited[make_pair(r, c)])
r--;
if (s[i] == 'E')
while (visited[make_pair(r, c)])
c++;
if (s[i] == 'S')
ll ans = INF;
for(int color = 1; color < N-1; color++){
for(int ind = 0; ind < dogs[color].size(); ind++){
if(ind+1 > k)
break;
for(int taken = 0; taken <= k - ind - 1; taken++)
ans = min(ans, dogs[color][ind] + pre[color-1][taken] + suf[color+1][k - taken - ind - 1]);
}
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sa=0, se=0;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++)
cin>>a[i];
for(int j=0;j<n-1;j++)
sa=sa+a[j];