├── hard ├── DiskStack.py ├── FindLoop.py ├── HeapSort.py ├── Knapsack.py ├── MinJumps.py ├── MinReward.py ├── QuickSort.py ├── WaterArea.py ├── BoggleBoard.py ├── FourNumberSum.py ├── LargestRange.py ├── MaxPathSumBst.py ├── PatternMatcher.py ├── QuickSelect.py ├── SearchForRange.py ├── SubarraySort.py ├── TopologicalSort.py ├── ContinuousMedian.py ├── LowestCommonManger.py ├── MultiStringSearch.py ├── ShiftedBinarySearch.py ├── UnderscorifySubstring.py ├── LongestSubstringNonDuplicate.py └── MaxSumIncreasingSubsequece.py ├── medium ├── Kadane.py ├── MinHeap.py ├── PowerSet.py ├── 3numberSum.py ├── BstTraversal.py ├── CoinChange.py ├── Levenshtein.py ├── MakeChange.py ├── MinMaxStack.py ├── Permutation.py ├── RemoveKthNode.py ├── RiverSizes.py ├── SingleCycle.py ├── SuffixTrie.py ├── ValidateBst.py ├── BalancedBracket.py ├── BreadthFirstSearch.py ├── BstConstruction.py ├── InvertBinaryTree.py ├── SmallestDifference.py ├── SortedMatrixSearch.py ├── MaxSubsetSumNoAdjacent.py ├── YoungestCommonAncestor.py └── LongestPalindromicSubstring.py ├── veryhard ├── LruCache.py ├── MergeSort.py ├── IterativeInorder.py ├── KmpAlgorithm.py ├── KTransacationMaxProfit.py ├── MinCutsPalindromePartition.py └── NumberOfBinaryTreeTopologies.py ├── extremelyhard ├── airport.py └── LongestCommonSubsequence.py ├── _config.yml ├── README.md ├── .vs ├── slnx.sqlite ├── algoexpert │ └── v16 │ │ └── .suo └── VSWorkspaceState.json ├── .vscode └── settings.json └── easy ├── java ├── threelargestNumbers │ ├── ThreeLargestBruteForce.java │ ├── ThreeLargestUsingSort.java │ └── ThreeLargestOptimal.java ├── TwoSum │ ├── TwoSumBruteForce.java │ ├── TwoSumOptimal.java │ └── TwoSumUsingSortTwoPointer.java ├── ValidateSubsequence │ ├── ValidateSubsequenceBruteForce.java │ └── validateSubseqOptimal.java ├── selectionSort │ └── SelectionSorting.java └── bubbleSort │ └── BubbleSortalgo.java ├── C# └── TwoSum.cs └── python ├── threelargest ├── threeLargestUsingSort.py └── threeLargestUsingHeaps.py ├── NthFibonacci.py ├── twoSum ├── twoSumOptimal.py ├── twoSumBruteForce.py └── twoSumTwoPointer.py ├── validateSubsequence └── Validate_Sequence.py ├── DepthFirstSearch.py └── branchSums.py /hard/DiskStack.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/FindLoop.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/HeapSort.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/Knapsack.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/MinJumps.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/MinReward.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/QuickSort.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/WaterArea.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/Kadane.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/MinHeap.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/PowerSet.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/BoggleBoard.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/FourNumberSum.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/LargestRange.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/MaxPathSumBst.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/PatternMatcher.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/QuickSelect.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/SearchForRange.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/SubarraySort.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/TopologicalSort.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/3numberSum.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/BstTraversal.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/CoinChange.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/Levenshtein.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/MakeChange.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/MinMaxStack.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/Permutation.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/RemoveKthNode.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/RiverSizes.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/SingleCycle.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/SuffixTrie.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/ValidateBst.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/LruCache.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/MergeSort.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /extremelyhard/airport.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/ContinuousMedian.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/LowestCommonManger.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/MultiStringSearch.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/ShiftedBinarySearch.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/BalancedBracket.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/BreadthFirstSearch.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/BstConstruction.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/InvertBinaryTree.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/SmallestDifference.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/SortedMatrixSearch.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/IterativeInorder.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/KmpAlgorithm.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/UnderscorifySubstring.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/MaxSubsetSumNoAdjacent.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/YoungestCommonAncestor.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /hard/LongestSubstringNonDuplicate.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hard/MaxSumIncreasingSubsequece.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /medium/LongestPalindromicSubstring.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/KTransacationMaxProfit.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/MinCutsPalindromePartition.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /extremelyhard/LongestCommonSubsequence.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /veryhard/NumberOfBinaryTreeTopologies.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 100 standard interview problems 2 | -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssjsatish/100-Interview-Problems/HEAD/.vs/slnx.sqlite -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.linting.pylintEnabled": true, 3 | "python.linting.enabled": true 4 | } -------------------------------------------------------------------------------- /.vs/algoexpert/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssjsatish/100-Interview-Problems/HEAD/.vs/algoexpert/v16/.suo -------------------------------------------------------------------------------- /easy/java/threelargestNumbers/ThreeLargestBruteForce.java: -------------------------------------------------------------------------------- 1 | package threelargestNumbers; 2 | 3 | public class ThreeLargestBruteForce { 4 | 5 | } -------------------------------------------------------------------------------- /easy/C#/TwoSum.cs: -------------------------------------------------------------------------------- 1 | public class TwoSum { 2 | public static int[] TwoNumberSum(int[] array, int targetSum) { 3 | 4 | return null; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /easy/python/threelargest/threeLargestUsingSort.py: -------------------------------------------------------------------------------- 1 | # O(nlogn) Simple but not the best 2 | def findThreeLargestNumbers(array): 3 | array.sort() 4 | return array[-3:] -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "", 4 | "\\easy" 5 | ], 6 | "SelectedNode": "\\easy\\NthFibonacci.py", 7 | "PreviewInSolutionExplorer": false 8 | } -------------------------------------------------------------------------------- /easy/python/threelargest/threeLargestUsingHeaps.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | def findThreeLargestNumbers(array): 3 | heaps = array 4 | heapq.heapify(heaps) 5 | return sorted(heapq.nlargest(3, heaps)) -------------------------------------------------------------------------------- /easy/python/NthFibonacci.py: -------------------------------------------------------------------------------- 1 | def getNthFib(n): 2 | a = 0 3 | b = 1 4 | counter = 3 5 | while counter <= n: 6 | fib = a + b 7 | a,b = b,fib 8 | counter +=1 9 | return b if n>1 else fib 10 | 11 | n = 6 12 | print(getNthFib(n)) -------------------------------------------------------------------------------- /easy/python/twoSum/twoSumOptimal.py: -------------------------------------------------------------------------------- 1 | 2 | # Approach #02 3 | ''' 4 | Using a hash/dictionary to lookup if 5 | Time: O(n) 6 | Space: O(n) 7 | ''' 8 | def twoSumUsingDictionary(ar, k): 9 | d = {} 10 | for i in range(len(ar)): 11 | if k-ar[i] in d: 12 | return sorted([k-ar[i], ar[i]]) 13 | else: 14 | d[ar[i]] = True 15 | return [] -------------------------------------------------------------------------------- /easy/python/twoSum/twoSumBruteForce.py: -------------------------------------------------------------------------------- 1 | # Approach #01 2 | ''' 3 | Using 2 loops to check every combination if there is a pair whose sum equals to the given number. 4 | Time: O(n^2) 5 | Space: O(1) 6 | ''' 7 | def twoSum(ar, k): 8 | for i in range(len(ar)-1): 9 | for j in range(i+1, len(ar)): 10 | if((ar[i]+ar[j])==k): 11 | return sorted([ar[i],ar[j]]) 12 | return [] -------------------------------------------------------------------------------- /easy/python/validateSubsequence/Validate_Sequence.py: -------------------------------------------------------------------------------- 1 | ''' 2 | array = [5,1,22,25,6,-1,8,10] 3 | sequence = [1,6,-1,10] 4 | 5 | check if sequence is subsequence of array 6 | ''' 7 | 8 | def isValidSubsequence(array, sequence): 9 | result = True 10 | for i in sequence: 11 | if i in array: 12 | array = array[array.index(i)+1:] 13 | else: 14 | return False 15 | return result -------------------------------------------------------------------------------- /easy/python/DepthFirstSearch.py: -------------------------------------------------------------------------------- 1 | ''' 2 | // for the depthFirstSearch method. 3 | // Feel free to add new properties 4 | // and methods to the class. 5 | // Do not edit the class below except 6 | ''' 7 | class Node { 8 | constructor(name) { 9 | this.name = name; 10 | this.children = []; 11 | } 12 | 13 | addChild(name) { 14 | this.children.push(new Node(name)); 15 | return this; 16 | } 17 | 18 | depthFirstSearch(array) { 19 | // Write your code here. 20 | } 21 | } 22 | 23 | // Do not edit the line below. 24 | exports.Node = Node; 25 | -------------------------------------------------------------------------------- /easy/python/branchSums.py: -------------------------------------------------------------------------------- 1 | class BinaryTree: 2 | def __init__(self, value): 3 | self.left = None 4 | self.right = None 5 | self.value = value 6 | def branchSums(root): 7 | sums = [] 8 | branchSumsRecurse(root, 0, sums) 9 | def branchSumsRecurse(node, runningSum, sums): 10 | if node is None: 11 | return 12 | newRunningSum = runningSum + node.value 13 | if node.left is None and node.right is None: 14 | sums.append(newRunningSum) 15 | return 16 | branchSumsRecurse(node.left, newRunningSum, sums) 17 | branchSumsRecurse(node.right, newRunningSum, sums) -------------------------------------------------------------------------------- /easy/python/twoSum/twoSumTwoPointer.py: -------------------------------------------------------------------------------- 1 | # Approach #03 2 | ''' 3 | Using a sort function to sort the given list first then use binary search method. 4 | Time: O(n log(n)) 5 | Space: O(1) 6 | ''' 7 | def twoSumUsingSort(ar, k): 8 | ar.sort() 9 | left = 0 10 | right = len(ar)-1 11 | while left < right: 12 | twoSum = ar[left]+ar[right] 13 | if twoSum == k: 14 | return sorted( [ ar[left], ar[right] ] ) 15 | elif twoSum < k: 16 | left = left + 1 17 | elif twoSum > k: 18 | right = right - 1 19 | return [] -------------------------------------------------------------------------------- /easy/java/threelargestNumbers/ThreeLargestUsingSort.java: -------------------------------------------------------------------------------- 1 | package threelargestNumbers; 2 | 3 | import java.util.Arrays; 4 | 5 | 6 | public class ThreeLargestUsingSort { 7 | public static void main(String[] args) { 8 | int[] array = new int[] {141,1,17,-7,-17,-27,18,541,8,7,7}; 9 | int[] result = find3Largest(array); 10 | System.out.println(result[0]+","+result[1]+","+result[2]); 11 | } 12 | 13 | private static int[] find3Largest(int[] array) { 14 | int[] temp = new int[3]; 15 | 16 | Arrays.sort(array); 17 | 18 | int i=2; 19 | int k=0; 20 | while(i>-1){ 21 | temp[k]=array[array.length-1-i]; 22 | i--; 23 | k++; 24 | } 25 | return temp; 26 | } 27 | 28 | 29 | } -------------------------------------------------------------------------------- /easy/java/TwoSum/TwoSumBruteForce.java: -------------------------------------------------------------------------------- 1 | package TwoSum; 2 | 3 | public class TwoSumBruteForce { 4 | 5 | public static int main(String[] args) { 6 | int[] array = {3,-4,5,8,11,-1,1,6}; 7 | int targetSum = 10; 8 | int[] result = twoNumberSum(array, targetSum); 9 | return result[0]+result[1]; 10 | } 11 | public static int[] twoNumberSum(int[] array, int targetSum) { 12 | int len= array.length; 13 | for(int i=0;i map = new HashMap<>(); 15 | for (int i : array) { 16 | int potMatch = targetSum-i; 17 | if(map.containsKey(potMatch)){ 18 | return new int[] {map.get(potMatch),potMatch}; 19 | } 20 | else 21 | { 22 | map.put(i,potMatch); 23 | } 24 | } 25 | return new int[] {}; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /easy/java/ValidateSubsequence/ValidateSubsequenceBruteForce.java: -------------------------------------------------------------------------------- 1 | package ValidateSubsequence; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class ValidateSubsequenceBruteForce { 7 | public static void main(String[] args) { 8 | List array = Arrays.asList (5, 1, 22, 25, 6, -1, 8, 10); 9 | List sequence = Arrays.asList (1, 6, -1, -1); 10 | boolean result = isValidSubsequence(array,sequence); 11 | System.out.println(result); 12 | } 13 | 14 | 15 | public static boolean isValidSubsequence(List array, List sequence) { 16 | int k=0; 17 | for(int i=0;i array = Arrays.asList (5, 1, 22, 25, 6, -1, 8, 10); 9 | List sequence = Arrays.asList (1, 6, -1, -1); 10 | boolean result = isValidSubsequence(array,sequence); 11 | System.out.println(result); 12 | } 13 | 14 | public static boolean isValidSubsequence(List array, List sequence) { 15 | for(int i = 0; i maxHeap = new PriorityQueue(); 13 | int[] resultArray = new int[3]; 14 | for (Integer integer : array) { 15 | if (maxHeap.contains(integer * (-1))) { 16 | maxHeap.offer(integer * (-1)); 17 | } 18 | maxHeap.add(integer * (-1)); 19 | 20 | } 21 | int count = 2; 22 | Iterator itr = maxHeap.iterator(); 23 | while (itr.hasNext() && count > -1) { 24 | resultArray[count--] = (int) itr.next() * (-1); 25 | } 26 | Arrays.sort(resultArray); 27 | // return resultArray; 28 | System.out.println(resultArray[0] + "," + resultArray[1] + "," + resultArray[2]); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /easy/java/bubbleSort/BubbleSortalgo.java: -------------------------------------------------------------------------------- 1 | package bubbleSort; 2 | 3 | public class BubbleSortalgo { 4 | static int count = 0; 5 | public static void main(String[] args) { 6 | 7 | int[] result = bubbleSort(new int[] { 8, 5, 2, 9, 5, 6, 3 }); 8 | for (int i : result) { 9 | System.out.print(i + ","); 10 | 11 | } 12 | System.out.println("\nNumber of swaps : "+count); 13 | } 14 | 15 | public static int[] bubbleSort(int[] array) { 16 | 17 | // logic for iterating the array 18 | for (int k = 0; k < array.length; k++) { 19 | int i=0; 20 | for (int j = 1; j < array.length; j++) { 21 | if (array[i] > array[j]) { 22 | swap(array, i, j); 23 | count++; 24 | i++; 25 | } else if (array[i] == array[j]) { 26 | i++; 27 | } else if (array[i] < array[j]) { 28 | i++; 29 | } 30 | 31 | } 32 | } 33 | // logic for swapping 34 | 35 | return array; 36 | } 37 | 38 | private static void swap(int[] array, int i, int j) { 39 | int tempVar = array[i]; 40 | array[i] = array[j]; 41 | array[j] = tempVar; 42 | } 43 | } 44 | --------------------------------------------------------------------------------