This repo contains a collection of common Algorithms and Data Structures questions. The implementation is in Java. The questions mentioned below, or a variation of the questions are common for coding interviews. Most of the solutions have test cases which checks their validity. The time and space complexity for each solution is also mentioned.
- Reverse an array without using extra space.
- Get the minimum and maximum element in an array.
- Find the Max and Second Max element in an array.
- Move negative elements to the left of the array.
- Rotate and array N number of times in O(n) time.
- Get the nth smallest element in an array in O(n) time.
- Sort an array which contains only 0, 1 and 2 in O(n) time and O(1) space.
- Merge 2 sorted arrays.
- Find the largest sub array in O(n) time.
- Find all duplicate numbers in an array.
- Find the duplicate number in an array of N + 1 integers.
- Merge 2 sorted arrays without using extra space.
- Kadanes Algorithm.
- Window Sliding.
- Given an array of integers of size ‘n’, calculate the maximum sum of ‘k’ consecutive elements in an array.
- Return the number of times a given pattern appears in a string.
- Minimum Deletions to Make Character Frequencies Unique.
- Three Number Sum
- Move Zero's to the left while preserving the order of elements.
- Smallest Difference. Given 2 non-empty arrays, find a pair of numbers who absolute difference is close to zero.
- Move a given element to the right side of the array.
- Urlify a given string without using extra space.
- Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target
- Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.
- Find the factorial of a number.
- Find the sum of the digits of a given number.
- Reverse a string.
- Check if a string is a palindrome.
- Find the subsequence of two strings
- Find all unique permutations in an array
- PreOrder Traversal
- InOrder Traversal
- PostOrder Traversal
- Breadth First Search
- Breadth First Search Each line
- Height of a Binary Tree
- Invert a Binary Tree
If you find a bug, or a better way to implement, please raise a pull request.