Skip to content

Instantly share code, notes, and snippets.

View sreeprasad's full-sized avatar

Sreeprasad sreeprasad

  • BlackRock
  • New York
View GitHub Profile
@sreeprasad
sreeprasad / htmltoPDF
Created August 2, 2012 05:18
Convert html to pdf using iText and Flying Saucer.
String inputFile = "~/github/iText/myhtml.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "~/github/iText/generated.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
@sreeprasad
sreeprasad / Learning prototype
Created August 8, 2012 11:02
From LinkedIn Techtalk
function calc(x){
thix.x=1;
this.x+=y
}
funciton Foo(){
}
Foo.prototype.result= new function{
@sreeprasad
sreeprasad / Marketing
Created September 2, 2012 20:26
My attempt to solve marketing problem from TopCoder
public class Marketing{
private static int N,M,i,j,totalValue=0,total=1;;
private static boolean [][]adj;
private static String inner;
private static String innerString[];
private static int color[];
private static boolean oddCycle=false;
@sreeprasad
sreeprasad / Circuits.java
Created September 2, 2012 20:28
My attempt to solve circuits problem from TopCoder
public class Circuits{
/* initalize variable */
private static int N,M,j,i;
private static String inner,innerCost;
private static String innerCircuit[],innerCircuitCost[];
private static boolean adj[][];
private static int innerCircuitAdj[][];
public static void main(String abd[]){
@sreeprasad
sreeprasad / MergeSort.java
Last active August 29, 2015 13:57
MergeSort and Counting Inversions.
private static int nInversions=0;
/** call helper function here */
public static void sort(Comparable[]a){
int lo=0,hi=a.length-1;
Comparable [] aux = new Comparable[a.length];
nInversions = sort(a,aux,lo,hi);
}
public static int coins(int []deno, int amount){
int dp[] = new int[amount+1];
dp[0]=0;
for(int j=1;j<=amount;j++){
dp[j]=Integer.MAX_VALUE;
for(int i=0;i<deno.length;i++){
if(deno[i]<=j && (1+dp[j-deno[i]] < dp[j]) )
dp[j]=1+dp[j-deno[i]];
}
}
@sreeprasad
sreeprasad / Word Break
Created July 20, 2014 14:02
Word Break Solution Leet Code
public class Solution {
public boolean wordBreak(String s, Set<String> dict) {
if( (dict.size()==0)||(s.length()==0))
return false;
if(s.length()==1 && !dict.contains(s))
return false;
else if(s.length()==1 && dict.contains(s))
@sreeprasad
sreeprasad / Reorder
Created September 24, 2014 03:08
Reorder List
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
@sreeprasad
sreeprasad / LinkListSort
Created September 24, 2014 03:12
Sort Linked List
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
@sreeprasad
sreeprasad / InsertionSortLinkedList
Created September 24, 2014 03:15
Insertion Sort Linked List
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }