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
from collections import Counter | |
s= input() | |
c= Counter(s) | |
cc= sorted(c.items(), key= lambda x: x[1], reverse= True) | |
huff_map= {} | |
a, b= '0', '1' | |
for x in range(len(cc)-1): | |
huff_map[cc[x][0]]= a*x + b #assigns 0, 01, 001 to n-1 chars | |
huff_map[cc[x+1][0]]= a* (len(cc)-1) #assigns 000..0 to nth char | |
print(huff_map) #prints the huffman mapping |
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" | |
"index/suffixarray" | |
) | |
func main() { | |
//readn_arr() | |
suffixarray_usage() |
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" | |
"sort" | |
) | |
func main() { | |
a:= []int{1,2,3,9,5,6} | |
fmt.Println(a) |
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
import itertools | |
def pretty(a): | |
for i in a: | |
print(i) | |
print() | |
original= [[1,2], [3,4]] | |
pretty(original) | |
pretty(original[::-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
''' | |
three sum, to find a+b+c== x in an array | |
''' | |
a= [-1,0,1,2,-1,-4] #the array/ list | |
x= 0 #the sum we need | |
s= set() | |
res= [] #holds groups of 3 numbers satisfying the condition | |
for i in range(len(a)-1): | |
ax= a[i] |
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
import java.util.ArrayList; | |
class Employee { | |
private String name; | |
private int empID; | |
private int yearsOfService; | |
private int salary; | |
private ArrayList<Certificate> certificates; | |
public Employee(String name, int empID, int yearsOfService, int salary) { |
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
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.Statement; | |
import java.sql.ResultSet; | |
import java.sql.ResultSetMetaData; | |
import java.sql.PreparedStatement; | |
/* | |
NOTES | |
-JDBC API is available in two packages, java.sql and javax.sql |
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
a= [ | |
[1,2,3,4], | |
[5,6,7,8], | |
[9,10,11,12], | |
[13,14,15,16] | |
] | |
for _ in a: | |
print(*_) | |
print() | |
ab= [x[::-1] for x in zip(*a)] |
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
#include <iostream> | |
using namespace std; | |
void merge_em_all(int *a, int *b, int *c, int x, int y, int z) { | |
int i=0, j=0, k= 0; | |
for(i=0, j=0; i<x && j<y; ) { | |
if(a[i]< b[j]){ |
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
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
int compare(const void *a, const void *b){ | |
return (*(int *)a- *(int*)b); | |
} | |
int str_compare(const void *a, const void *b) { |