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 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: |
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 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 | |
* |
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 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) |
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 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) |
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 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 |
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 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 { |
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 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 |
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 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) |