Skip to content

Instantly share code, notes, and snippets.

def coinChange(coins, amount):
def solve(amt):
if amt < 0:
return float('inf')
if amt == 0:
return 0
if amt in memo:
return memo[amt]
ans = float('inf')
for c in coins:
#include <iostream>
#include <queue>
using namespace std;
enum COLOR { RED, BLACK };
class Node {
public:
int val;
COLOR color;
#include <bits/stdc++.h>
using namespace std;
struct node {int key; struct node *left, *right;};
struct node* newNode(int item)
{
struct node* temp
= (struct node*)malloc(sizeof(struct node));
@u7karshs
u7karshs / IITG.sh
Last active October 26, 2022 03:16
#!/bin/bash
url_encode() {
awk 'BEGIN {
for (n = 0; n < 125; n++) {
m[sprintf("%c", n)] = n
}
n = 1
while (1) {
s = substr(ARGV[1], n, 1)
if (s == "") {
/*
{ string s[30];
for(int i=0 ; cin.peek()!='\n';++i){
cin>>s[i];cout<<s[i]<<endl;}
*/
//*******************************
/*
string s[30];
int i=0;
@u7karshs
u7karshs / tblcitylist.sql
Created October 10, 2020 13:47 — forked from sivaprabug/tblcitylist.sql
MySQL database of Indian Cities and states,latitude and longitude..
-- phpMyAdmin SQL Dump
-- version 3.5.2.2
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Apr 08, 2013 at 02:48 PM
-- Server version: 5.5.27
-- PHP Version: 5.4.7
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
@u7karshs
u7karshs / lastDigit_sumFibonacci.py
Created June 20, 2020 11:00
Last digit of sum of n i.e till (Fn) term
# Uses python3
import array as arr
def summ(ara,t):
s=0
for i in range (0,t):
s=s+ara[i]
return s
def fiboH(n):
@u7karshs
u7karshs / Fibonacci_mod_n.py
Created June 20, 2020 10:58
Huge fubonacci % n
import array as arr
def fiboH(n,m):
ar=arr.array('L',[0])
ar.append(1)
p=-1
a=0
b=1
for i in range (2,n+1):
c=b+a
@u7karshs
u7karshs / Fast_LCM.cpp
Last active June 20, 2020 10:53
(c++/int64_t) LCM=(a*b)/GCD
#include <iostream>
int64_t GCD(int64_t a, int64_t b){
if(b==0)
return a;
a=a%b;
return GCD(b,a);
}
int main() {
int64_t a, b;
std::cin >> a >> b;
@u7karshs
u7karshs / Fast_GCD.cpp
Last active June 20, 2020 10:54
Fast GCD using property (c++)
#include <iostream>
int64_t gcd(int64_t a, int64_t b) {
if(b==0)
return a;
a=a%b;
return gcd(b,a);
}
int main() {
int64_t a, b;
std::cin >> a >> b;