#x Problem Solving Questions
Here is a non-exhaustive list of problem-solving questions.
- Pre-read:
- Time and Space Complexity
- Big O CheatSheet
- Worst case scenario to be considered when benchmarking
- If Java is your programming language to solve, here is the Collections framework overview chart
Questions #
| 1 | fizz-buzz | |
| 2 | Warmup-2 > stringYak | HINT: Scan char by char having condition like if “yak” is found jump the pointer to 3 chars at once |
| 3 | Warmup-2 > last2 | HINT: use substring and equals() Question description is confusing. Focus on sample input and output. Count the last 2 chars substring in given string except the last 2chars. |
| 4 | Warmup-2 > arrayCount9 | HINT: Use 2-pointer |
| 5 | Warmup-2 > countXX | |
| 6 | Warmup-2 > stringX | |
| 7 | Warmup-2 > has271 | HINT: Math.abs(third - (first-1)) <= 2 |
| 8 | Warmup-2 > altPairs | HINT: Jump by 2 chars but ensure there is no java.lang.StringIndexOutOfBoundsException |
| 9 | String1 > minCat | |
| 10 | String-1 > without2 | HINT: With overlapping sample input and output XXX -> "x". Handle Edge cases: Single char strings like “” or “x” |
| 11 | String-1 > startWord | |
| 12 | String-2 > xyzThere | HINT: Repetition possible. Example: abc.xyzxyz |
| 13 | String-1 > withoutX | |
| 14 | String-1 > withoutX2 | |
| 15 | minimum-moves-to-equal-array-elements | |
| 16 | minimum-moves-to-equal-array-elements-ii | |
| 17 | longest-happy-string | |
| 18 | fibonacci-number | |
| 19 | reverse-integer |
NOTE: In math division we have 2 parts - remainder and quotient. In programming we use
%operator to find the remainder and/operator to find the quotient- Example Algorithm/pseudocode
Given a number 123
Divide by 10
123 / 10 = 12(quotient)
123 % 10 = 3(remainder)
initialize 3 vars reverse=0, remainder=0, number=123
while(number != 0) {
remainder = number % 10;
reverse = reverse*10 + remainder;
number /= 10;
}
Finally, the reverse var has the reversed value
| 20 | gcd-of-two-numbers | Refer Algorithm: Euclidian Algorithm |
| 21 | armstrong-number Alternative Link: armstrong-numbers |
|
| 22 | palindrome-number Note: Solve it without converting the input to String |
|
| 23 | Give a string in form of char[] reverse it in place Note: Solve it in-place |
HINT: 2 pointers at front and back, break the loop when i < j and swap chars |
| 24 | two-sum | |
| 25 | three-sum | |
| 26 | contains-duplicate | |
| 27 | valid-anagram | |
| 28 | Valid Parentheses | HINT: java.util.Stack(push, peek, pop) + switch statement |
| 29 | kth-largest-element-in-an-array Note: Solve it without Sorting |
HINT: with offer() load the given array into PriorityQueue(ADT)(Initialize the priority queue as max-heap passing Comparator.reverseOrder()) and poll() the head k times |
| 30 | best-time-to-buy-and-sell-stock | |
| 31 | Reverse a Linked list |
| 32 | Remove Linked List elements | |
| 33 | Move Zeros | |
| 34 | Max Sub array sum | |
| 35 | Top k Frequent elements | |
| 36 | Rotate array to right k steps | |
| 37 | LRU Cache |
- HINT:
- Option1:
LinkedList(Is a Doubly LinkedList in Java) +HashMap - Option2:
int capacity = 2; LinkedHashMap<Integer, Integer> lhs = new LinkedHashMap<>(capacity, 0.75f, true) { @Override protected boolean removeEldestEntry(java.util.Map.Entry<Integer, Integer> eldest) { return size() > capacity; } }; - Option1:
| 38 | Reverse words in a string | |
| 39 | Reverse Words | |
| 40 | Array-1 > unlucky1 |


