Skip to content

Instantly share code, notes, and snippets.

View meghakrishnamurthy's full-sized avatar

Megha Krishnamurthy meghakrishnamurthy

View GitHub Profile
@meghakrishnamurthy
meghakrishnamurthy / IsomorphicStrings.java
Created July 13, 2016 04:46
Isomorphic Strings - Java implementation
package megha.codingproblems.strings;
import java.util.HashMap;
import java.util.Map;
/**
* Git source URL - https://github.com/meghakrishnamurthy/CodingProblems/blob/master/src/megha/codingproblems/strings/IsomorphicStrings.java
* Program to find if 2 given alphabetic strings are isomorphic.
* Two strings are isomorphic if the characters in string A can be replaced to get string B
* Time complexity - O(n)
@meghakrishnamurthy
meghakrishnamurthy / MergeInterval.java
Created July 5, 2016 07:51
Merge Intervals - Java implementation
package megha.codingproblems.arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Merge intervals program
* Github link: https://github.com/meghakrishnamurthy/CodingProblems/blob/master/src/megha/codingproblems/arrays/MergeInterval.java
@meghakrishnamurthy
meghakrishnamurthy / Fibonacci.java
Created July 5, 2016 07:49
Fibonacci - Recursive and Iterative implementation in Java
package megha.codingproblems.general;
/**
* Fibonacci program - Both iterative and recursive versions
* Fibonacci series - 1,1,2,3,5,8,13....
*
* @author megha krishnamurthy
*
*/
public class Fibonacci {
@meghakrishnamurthy
meghakrishnamurthy / TwoSum.java
Created July 5, 2016 04:10
Two Sum problem - Java implementation
package megha.codingproblems.arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Program to solve the 2 sum problem
* Problem statement - Given an array of integers, find two numbers such that they add up to a specific target number
@meghakrishnamurthy
meghakrishnamurthy / DepthFirstSearch.java
Created July 5, 2016 01:18
Depth First Search of a binary tree - Java implementation
package megha.codingproblem.trees;
import java.util.Stack;
/**
* Git repo link - https://github.com/meghakrishnamurthy/CodingProblems/blob/master/src/megha/codingproblem/trees/DepthFirstSearch.java
*
* Depth first search implementation using a Stack
*
* Time complexity - O(n)
@meghakrishnamurthy
meghakrishnamurthy / MirrorBinaryTree.java
Created July 5, 2016 00:54
Java implementation of mirroring Binary Tree
package megha.codingproblem.trees;
/**
* Git Repo link: https://github.com/meghakrishnamurthy/CodingProblems/blob/master/src/megha/codingproblem/trees/MirrorBinaryTree.java
*
* Class to perform mirroring of a binary tree
* Time Complexity - O(n)
* Space Complexity:
* O(h) where h is the height of the binary tree
* Best/average case - O(logn)
@meghakrishnamurthy
meghakrishnamurthy / LevelOrderTraversal.java
Created July 5, 2016 00:24
BFS or Level order traversal of binary tree - implementation in Java
package megha.codingproblem.trees;
import java.util.LinkedList;
import java.util.Queue;
/**
* Class to perform a level order traversal or BFS on a binary tree
* Time complexity - O(n)
* Space complexity - Average of O(1) and worst case of O(n)
* @author megha krishnamurthy
*
@meghakrishnamurthy
meghakrishnamurthy / PreorderInorderPostorder.java
Created July 5, 2016 00:22
Preorder, Inorder and Postorder traversal of Binary tree implementation in Java
package megha.codingproblem.trees;
/**
* Class to perform the different DFS traversals on a binary tree:
* 1. Pre order traversal
* 2. In order traversal
* 3. Post order traversal
*
* Time complexity of these operations - O(n)
* Space complexity of these operations: