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
/* The code allows rotation of an 1D array (right and left) | |
using XOR operator | |
ie. Shifts elements of an Array to left or right directions, | |
wraps the elements circularly. | |
*/ | |
#include <stdio.h> | |
int arr[]={1,2,3,4,5,6,7,8,9,10}; |
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
//SIMPLE INTERMEDIATE CODE GENERATOR (3 ADDRESS CODE) | |
//Author: Rupal Barman | |
//Modified: 5/11/16 | |
// Does not consider the operator precedence, ie. generates the 3 address code from left to right directly. | |
// INPUT example: t = q * p + g ; (don't forget to end the statement with a ';' or any character, even a space would work) | |
// OUTPUT example: v=r*j; w=v+h | |
#include <iostream> | |
#include <stdio.h> | |
#include <string.h> |
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
''' | |
Binary Searc Tree Simple | |
Rupal Barman | |
[email protected] | |
This is a demonstration of implementing BST in python. | |
Since, it's basic. Feel free to add in more features. | |
''' | |
class Node(object): |
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
/* | |
Binary Search Tree GoLang | |
Rupal barman | |
[email protected] | |
*/ | |
package main | |
import ( | |
"fmt" |
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
# get adjancy matrix | |
n= int(input()) #number of vertices | |
am=[] | |
for i in range(n): | |
am.append([int(x) for x in input().split()]) | |
print(am) #show matrix | |
print() | |
#conver to adjancy list |
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
def get_pair_with_sum(a, need): | |
s= set() | |
for i in a: | |
if (need- i) in s: | |
print(need-i, i) | |
else: | |
s.add(i) | |
a=[4,2,4,2] | |
b=[3,6,2,5] |
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
# bin packing algo (estimation) | |
# since it is Np- Hard | |
# for better methods (first fit and best fit) use self balancing trees | |
# this one is Next fit | |
def bins_needed(item_weights, bin_capacity): | |
remain= bin_capacity | |
bins=0 | |
for i in item_weights: | |
if i> bin_capacity: |
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
#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)) |
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
''' | |
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 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); |
OlderNewer