Data Structures and Algorithms form the basic back bone of programming.
Whether you are creating a simple Hello World program or a complex enterprise application you are going to deal with data structures and algorithms.
Data structures are used to hold data temporarily or permanently.
Algorithms are ways to operate on that data to get your required output.
Product companies like Google , Facebook , Amazon etc evaluate candidates first based on their expertise on data structures and algorithms.
There are certain fixed categories of algorithms they prefer to ask during interviews.
Though these algorithms are hardly used in everyday programming at work, they are still used to screen entry level candidates.
Passing these tests require a lot of hard work and practice.
Note that we evaluate how good an algorithm is based on the time it takes to complete and the memory required on the computer to execute the program.
The lesser the time and the memory the better the algorithm is .
So candidates are expected to explain the time and space complexity of the algorithms they solve.
Here are top 100 algorithms asked during interviews with their solution in Java under different categories.
All these problems were solved on leetcode for optimal time complexity.
The time complexity and space complexity for each algorithm is also explained.
- Repeating Characters
- Valid Anagram
- Longest Repeating Character Replacement
- Minimum Window Substring
- Group Anagrams
- Valid Parantheses
- Valid Palindrome
- Longest Palindromic Substring
- Palindromic Substrings
- Encode and decode strings
- Roman to Integer
- First Unique character
- Excel sheet to column number
- Two Sum
- Best time to buy and sell stock
- Contains Duplicate
- Product of Array except self
- Maximum Subarray
- Maximum Product Subarray
- Minimum in Rotated Sorted Array
- Search in Rotated Sorted Array
- Three Sum
- Container with most water
- Longest consecutive sequence
- Longest common prefix
- Remove duplicates
- Plus One on an array
- Merge sorted array
- Valid Soduku
- Single non duplicate number in array
- Find the element which appears more than half the size
- Sort three colors
- Kth largest element
- First missing positive integer
- Peak element
- Next highest permutation
- Rotate array
- First and last position of element in sorted array
- Median of two sorted arrays
- Reverse Linked List
- Detect Cycle in Linked List
- Merge two sorted lists
- Reorder list
- Remove nth node from the last
- Merge k sorted lists
- Add two numbers represented by linked list
- Find if linked list is a palindrome
- Odd Even linked list
- Delete node given only the node
- Climbing Stairs
- Minimum Coin Change
- Longest Increasing Subsequence
- Longest Common Subsequence
- Word Break
- House Robber
- House Robber II
- Jump Game
- Combination Sum
- Decode Ways
- Unique Paths
- Valid Binary Tree
- Same tree or not
- Invert Binary Tree
- Maximum Path Sum in a Binary Tree
- Level Order Traversal
- Subtree of another tree
- Valid BST or not?
- Construct Binary tree from Preorder and Inorder Traversals
- Kth smallest element in BST
- Lowest Common Ancestor of two nodes in BST
- Serialize and Deserialize
- Inorder traversal
- Is Tree symmetric
Leave a Reply