Skip to content

Instantly share code, notes, and snippets.

@flexelem
flexelem / Dictionary.java
Created August 17, 2014 21:47
Prefix tree written by using Trie. Supports find prefixes in O(n.m.k) where k is length of the prefix and O(n.m) comes from Depth First Search
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Set;
public class Dictionary {
private TrieNode root;
public Dictionary() {
root = new TrieNode(null);
### Keybase proof
I hereby claim:
* I am flexelem on github.
* I am buraktas (https://keybase.io/buraktas) on keybase.
* I have a public key whose fingerprint is 7A85 0AFA 2966 A9D3 4373 47ED D57B 4F5E 6010 4B7C
To claim this, I am signing this object:
@flexelem
flexelem / ComputeSCC.java
Created May 19, 2014 21:41
Kosaraju's algorithm to find Strongly Connected Components
package compute_strongly_connected_components;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
public class ComputeSCC {
@flexelem
flexelem / FindCommonElementsInTwoArrays.java
Created June 13, 2014 14:41
Find common elements out of two sorted array
import java.util.ArrayList;
public class FindCommonElementsInTwoArrays {
public ArrayList<Integer> findCommonElementsOfTwoArray(int[] array1, int[] array2) {
int[] larger = array1;
int[] smaller = array2;
if (array1.length < array2.length) {
var AWS = require("aws-sdk");
var simpleParser = require("mailparser").simpleParser;
var s3 = new AWS.S3();
exports.handler = async (event, context, callback) => {
console.log("Invoked Lambda");
const mail = event.Records[0].ses.mail;
console.log("Mail");
@flexelem
flexelem / DoubleStack.java
Last active February 20, 2020 01:07
Two stacks in one array
import java.util.NoSuchElementException;
/**
* CLRS - Introduction to Algorithms Ex.10.1-2
* Explain how to implement two stacks in one array A[1..n] in such a way that
* neither stack overflows unless the total number of elements in both stacks together is n.
* The PUSH and POP operations should run in O(1) time.
*
* There are two stacks in one array which the first one grows upwards ( A[1..N] ),
* and the second one grows downwards ( A[N..1] ).
import {
CfnParameter, Construct, Stack, StackProps,
} from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import * as apigateway from '@aws-cdk/aws-apigateway';
import * as iam from '@aws-cdk/aws-iam';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import { ApiStackProps } from './entity';
export class CostApiStack extends Stack {
Resources:
costapi8876B5F2:
Type: AWS::ApiGateway::RestApi
Properties:
EndpointConfiguration:
Types:
- EDGE
Name: cost-api
Metadata:
aws:cdk:path: CostApiAlfa/cost-api/Resource
@flexelem
flexelem / minHeap.java
Created June 8, 2014 15:32
A min heap implementation in java.
import java.util.ArrayList;
public class MinHeap {
private ArrayList<Integer> list;
public MinHeap() {
this.list = new ArrayList<Integer>();
}