Tip 1 : Practice at least 10 problem on each topic of DS and Algo from easy to hard.
Tip 2 : Cover all the topics with basic operation and with their time complexity.
Tip 3 : Read about System Design approach - it is equally important when you have 2+ year of experience.
Tip 1 : Have some certification in the resume.
Tip 2 : Mention the proper keyword as per the role you are applying.
HR called for the interview availability. This round was set up during day time. This round was elimination round and based on DS and Algorithm problem.Overall the interview experience was really great. I was able to provide optimised solution for both DS Algo problem.


An array 'C' is a subarray of array 'D' if it can be obtained by deletion of several elements(possibly zero) from the beginning and the end of array 'D'. For example, all the non-empty subarrays of array [1,2,3] are [1], [2], [3], [1,2], [2,3], [1,2,3].
Input: 'N' = 3 , 'ARR' = [-5, 10 , 0]
Output: -5
Explanation : The non empty subarrays possible for 'ARR' are [-5], [10], [0], [-5, 10], [-5, 0], [10, 0], [-5, 10, 0]. The sum of the elements of these subarrays are -5, 10, 0, 5, -5, 10, 5. The minimum of them is -5.
Step: This problem was based on sliding window concepts:
public int minSubArrayLen(int target, int[] nums) {
int sum = 0;
int i =0;
int j = 0;
int ans = Integer.MAX_VALUE;
while(j= target){
ans = Math.min(ans, j-i+1);
sum -= nums[i];
i++;
}
j++;
}
return ans == Integer.MAX_VALUE ? 0 : ans;
}



Note: Since the number of ways can be very large, return the answer modulo 1000000007.
N=3

We can climb one step at a time i.e. {(0, 1) ,(1, 2),(2,3)} or we can climb the first two-step and then one step i.e. {(0,2),(1, 3)} or we can climb first one step and then two step i.e. {(0,1), (1,3)}.
Solution:
public int climbStairs(int n) {
int second = 0;
int first = 1;
for(int i=1; i<=n; i++){
int temp = first+second;
second = first;
first = temp;
}
return first;
}
This round was set up during day time. This round was elimination round and based on DS and Algorithm problem.Overall the interview experience was really great. I was able to provide optimised solution for both DS Algo problem.



Input: Consider the following Binary Tree:
Output:
Following is the level-order traversal of the given Binary Tree: [1, 2, 3, 5, 6, 4]
Step: I used queue to use this problem. Over all time complexity for this problem was linear.
public List> zigzagLevelOrder(TreeNode root) {
List> ans = new ArrayList();
if(root == null ) return ans;
Deque queue = new ArrayDeque();
int count = -1;
queue.add(root);
while(!queue.isEmpty()){
List list = new ArrayList();
int n = queue.size();
if(count == -1 ){
for(int i=0; i TreeNode node = queue.removeFirst();
list.add(node.val);
if(node.left != null ) queue.addLast(node.left);
if(node.right != null ) queue.addLast(node.right);
}
}else{
for(int i=0; i TreeNode node = queue.removeLast();
list.add(node.val);
if(node.right != null ) queue.addFirst(node.right);
if(node.left != null ) queue.addFirst(node.left);
}
}
ans.add(list);
count = -count;
}
return ans;
}



'arr '= [1,2,3,4,5]
'k' = 1 rotated array = [2,3,4,5,1]
'k' = 2 rotated array = [3,4,5,1,2]
'k' = 3 rotated array = [4,5,1,2,3] and so on.
Steps to solve the problem:
public void rotate(int[] arr, int k) {
int n = arr.length;
k = k%n;
reverse(arr, 0, n-1);
reverse(arr, 0, k-1);
reverse(arr, k, n-1);
}
public void reverse(int arr[], int start, int end){
while(start < end){
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
This round a system design round. Overall the interview experience was great. Interviewer was satisfied with the approach that I have given.



1. get(key) - Return the value of the key if the key exists in the cache, otherwise return -1.
2. put(key, value), Insert the value in the cache if the key is not already present or update the value of the given key if the key is already present. When the cache reaches its capacity, it should invalidate the least recently used item before inserting the new item.
Type 0: for get(key) operation.
Type 1: for put(key, value) operation.
1. The cache is initialized with a capacity (the maximum number of unique keys it can hold at a time).
2. Access to an item or key is defined as a get or a put operation on the key. The least recently used key is the one with the oldest access time.
Steps to solve this problem:
class LRUCache {
Map nodeMap;
DoublyLinkedList doublyLinkedList;
int capacity;
public LRUCache(int capacity) {
nodeMap = new HashMap();
doublyLinkedList = new DoublyLinkedList();
this.capacity = capacity;
}
public int get(int key) {
if(nodeMap.containsKey(key)){
Node node = nodeMap.get(key);
doublyLinkedList.removeGiven(node);
doublyLinkedList.addFirst(node);
return node.val;
}
return -1;
}
public void put(int key, int value) {
if(nodeMap.containsKey(key)){
Node node = nodeMap.get(key);
node.val = value;
doublyLinkedList.removeGiven(node);
doublyLinkedList.addFirst(node);
}else{
if(nodeMap.size() == capacity){
Node node = doublyLinkedList.getTail();
doublyLinkedList.removeLast();
nodeMap.remove(node.key);
}
Node node = new Node(key, value);
doublyLinkedList.addFirst(node);
nodeMap.put(key, node);
}
}
}
class DoublyLinkedList{
private Node head;
private Node tail;
public DoublyLinkedList(){
head = null;
tail = null;
}
public Node getHead(){
return head;
}
public Node getTail(){
return tail;
}
public void addFirst(Node node){
node.prev = null;
node.next = null;
if(head == null ){
head = node;
tail = node;
}else{
node.next = head;
head.prev = node;
head = node;
}
}
public void removeLast(){
if(tail == null ) return;
if(tail.prev == null ) {
tail = null;
head = null;
return;
}
tail.prev.next = null;
tail = tail.prev;
}
public void removeGiven(Node node){
if(node.prev == null ){
head = node.next;
if(node.next == null) tail = null;
else node.next.prev = null;
}else{
node.prev.next = node.next;
if(node.next == null) tail = node.prev;
else node.next.prev = node.prev;
}
}
}
class Node{
int val;
int key;
Node prev;
Node next;
public Node(int key, int val){
this.key = key;
this.val =val;
this.prev = null;
this.next = null;
}
}

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?