Skip to content

Instantly share code, notes, and snippets.

View Raghav2211's full-sized avatar
🏠
Working from home

Raghav Raghav2211

🏠
Working from home
View GitHub Profile
class Node{
int data;
Node left,right;
Node(int d){
data=d;
left=right=null;
}
}
class Solution
public static int coinChange(int[] coins, int amount, Map<Integer, Integer> map) {
if (map.get(amount) != null) return map.get(amount);
if (amount == 0) return 0;
if (amount < 0) return -1;
int minimumCoin = Integer.MAX_VALUE;
for (int coin : coins) {
int remainder = amount - coin;
int coinNeeded = coinChange(coins, remainder, map);
map.put(remainder, coinNeeded);
if (coinNeeded != -1) {
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if( (p.val == root.val || q.val == root.val) || ( p.val < root.val && q.val > root.val)){
return root;
}
TreeNode ans = root;
if(p.val< root.val && q.val < root.val ){ //left
ans = lowestCommonAncestor(root.left,p,q);
}
else if(p.val > root.val && q.val > root.val) { // right
@Raghav2211
Raghav2211 / TouchingTriangle.java
Created May 23, 2021 15:33
Touching triangle in java
public class TouchingTriangle {
public static void main(String[] args) {
touchingTriangle();
}
private static void touchingTriangle() {
int r = 10;
int qty = 10;
for (int iu = 1, id = r; iu <= r; ++iu, --id) {
package main
import (
"fmt"
)
var jobs = []int {1,2, 3, 4,5,6,7,8,9,10}
func producer ( link chan int , backpressure <- chan int) {
for {
backpressureEvent := <- backpressure
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
splitInput := strings.Split(s," ")
wordCount := make(map[string]int)
func fibonacci() func() int {
f1,f2 := 0,1
return func() int {
f2 , f1 = (f1+f2), f2 // https://golang.org/ref/spec#Order_of_evaluation
return f1
}
}