Focus on at-least Leetcode easy questions
Standard theory fundamental questions will be there
Be precise and avoid irrelevant points.
Put everything you have achieved.



You are given the array ‘ARR’ = [1, 1, 1, 1, 1], ‘TARGET’ = 3. The number of ways this target can be achieved is:
1. -1 + 1 + 1 + 1 + 1 = 3
2. +1 - 1 + 1 + 1 + 1 = 3
3. +1 + 1 - 1 + 1 + 1 = 3
4. +1 + 1 + 1 - 1 + 1 = 3
5. +1 + 1 + 1 + 1 - 1 = 3
These are the 5 ways to make. Hence the answer is 5.
int low = 0, high = nums.length-1;
while(low<=high){
int mid = low+(high-low)/2;
System.out.print(mid+" ");
if(nums[mid]==target) return mid;
if(nums[mid] else high = mid-1;
}



The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked list is 4 -> 3 -> 2 -> 1 -> NULL and the head of the reversed linked list will be 4.
Can you solve this problem in O(N) time and O(1) space complexity?
ListNode prev = null;
ListNode curr = head;
ListNode currNext = head;
while(curr!=null){
currNext = curr.next;
curr.next = prev;
prev = curr;
curr = currNext;
}
return prev;



The given linked lists may or may not be null.
If the first list is: 1 -> 4 -> 5 -> NULL and the second list is: 2 -> 3 -> 5 -> NULL
The final list would be: 1 -> 2 -> 3 -> 4 -> 5 -> 5 -> NULL
ListNode res = new ListNode(0);
ListNode newList = res;
while(list1!=null && list2!=null){
if(list1.val newList.next = new ListNode(list1.val);
newList = newList.next;
list1 = list1.next;
}
else{
newList.next = new ListNode(list2.val);
newList = newList.next;
list2 = list2.next;
}
}
if(list1==null) newList.next = list2;
else newList.next = list1;
return res.next;



A majority element is an element that occurs more than floor('N' / 2) times in the array.
int maj = nums[0];
int count = 0;
for(int i=0; i if(maj == nums[i]) count++;
else count--;
if(count == 0) {
maj = nums[i];
count = 1;
}
}
return maj;



A binary search tree is a binary tree data structure, with the following properties :
a. The left subtree of any node contains nodes with a value less than the node’s value.
b. The right subtree of any node contains nodes with a value equal to or greater than the node’s value.
c. Right, and left subtrees are also binary search trees.
It is guaranteed that,
d. All nodes in the given tree are distinct positive integers.
e. The given BST does not contain any node with a given integer value.



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