33 Must Know CP Question
function singleNumber(nums) {
let result = 0;
for (let i = 0; i < nums.length; i++) {
result ^= nums[i]; //bitwise XOR operation
}
return result;
}
Brute force Approach
class Solution {
public:
char findTheDifference(string s, string t) {
if (s.size() < 1)
return t[0];
unordered_map<char,int> mapping;
for (int i = 0; i < t.size(); i++) {
mapping[t[i]]++;
}
for (int i = 0; i < s.size(); i++) {
mapping[s[i]]--;
}
for (auto it : mapping) {
if (it.second != 0) {
return it.first;
}
}
return 'a';
}
};Optimal Approach
2. Reverse the array without any additional array! (Two Pointer Approach)
3. Given a number. Find the sum of the digits of the number ?
4. Merge these two sorted arrays using one loop?
5. Find out which is the last /previous palindrome number of a given number. (Example: 20 is given, so 11 is the palindrome number) [Reverse a Number]
6. An array of letters from a-z is given. Find out the first non-repeated letter. (like array [A, B,V,C,A,C,V,P] is given, here B is the first non-repeated letter).
8. How To Check If a Value Is A Power Of 2 Or Not ?
9.1. Find All Substrings of a String
9.2. Find Substring in a String
10. How do you swap two numbers without using a third variable
11. GCD of Two Numbers
12. A string of 9 characters will be given. There will be 3 blocks of 3 characters in the String. each character will have a numerical value. you need to find the sum of the numerical values of each block and then finally concave the answer of each block and form a string. rw-x-r-rw Here r = 4 , x = 2, w = 1, - = 0 What is the answer?
13. Write code to Calculate frequency of characters in a string
14. Write code Check if the given string is Palindrome or not
15. Find the Missing Number Between 1-N: 268. Missing Number
16. Write code to Check if two strings are Anagram or not : 242. Valid Anagram
17. 2nd Smallest Number in an Array
18. Write code of Perfect number (Divisors of a Number)
19. Write a code for Binary Search
20. Find non-repeating characters in a string
Overall Time Complexity
23. Find a number is a prime or not
24. Circular rotation of an array by K positions
25.Dynamic Programming: Climbing Stairs

27. Diameter of Binary Tree: The diameter of a binary tree is the length of the longest path between any two nodes in a tree.
28. Linked List Cycle: Determine if the linked list has a cycle in it.
29. Middle of the Linked List: If there are two middle nodes, return the second middle node.
32. Maximum Subarray
Last updated