Problems
July 13, 2022
Valid palindrome
We will take 2 pointers, at the beginning of the string and end of the string, then we compare both. If the character is not an aplhabet or number we move the pointer value by one. We also convert...
ReadJuly 13, 2022
Number of 1 bits
We can logical and any number with 1 to check whether the last bit of that number is 1 or 0. We can also check this by checking the number is odd or even. Odd numbers always has last bit as 1. We...
ReadJuly 13, 2022
Product of array except self
We can go thorugh the whole list once and caculate and store the multiplicatio of prefix indeies in the result array directly. That way we don't use any extra memory. Then we do the same thing but in...
ReadJuly 12, 2022
Group anagrams
We are given a list of strings. We can iterate through each string, and sort it charactes, then use this as key in a hashmap, and the value of the hashmap will be a list. We will append the original...
ReadJuly 12, 2022
Top k frequent element
We will count the frequency of each element and store it in a hashmap, where the number itself will be the key and frequency will be the value. Then we sort the elements of the hashmap and get the...
ReadJuly 12, 2022
Rotting oranges
This is a BFS problem. We have to count the number of steps as minutes to return. If we can't traverse the whole grid, then we will return -1. Only tricky part is we can have multiple rotten oranges...
ReadJuly 12, 2022
Valid anagram
We can split both string to characters, sort and then compare each characters at every position. If we don't find any match, we return False. After comparing every character, we will return True....
ReadJuly 11, 2022
Binary tree right side view
This problem asked us to return the list of the nodes when we look it from the right side. That means, if we traverse the whole tree with BFS, we will see the right side node of the tree in each...
ReadJuly 11, 2022
Max area of island
This is a classing grid graph problem. We will iterate through each row and column, when we find a new land, we will then expand the area of land sorrounding. We can use BFS or DFS to do that. I will...
Read