This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node{ | |
int data; | |
Node left,right; | |
Node(int d){ | |
data=d; | |
left=right=null; | |
} | |
} | |
class Solution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |