This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 <algorithm> | |
| #include <vector> | |
| using namespace std; | |
| int main() { | |
| int a[]= {1, 2, 90, 43, 23}; | |
| int b[]= {1, 90, 2, 43, 99}; | |
| vector<int> v(10); |
This file contains hidden or 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
| ''' | |
| Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency For example, bacdc and dcbac are anagrams, but bacdc and dcbad are not. | |
| Alice decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number? | |
| Given two strings, and , that may or may not be of the same length, determine the minimum number of character deletions required to make and anagrams. Any characters can be deleted from either of the strings. | |
| ''' | |
| from collections import Counter | |
| c1 = Counter('baaaaccd') | |
| c2 = Counter('abbaa') |
This file contains hidden or 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
| #generate all subsets of a sequence | |
| f = lambda x: [[y for j, y in enumerate(set(x)) if (i >> j) & 1] for i in range(2**len(set(x)))] | |
| print(f([1,2,3])) | |
| #print((2>>1)&1) #1010-> 0101 | |
| # max() using lambda | |
| maxx= lambda x,y: y if y>x else x | |
| print(maxx(23,12)) |