Problems
July 13, 2022
Single number
We can iterate through the entire array and XOR everything. For starter we start our result to 0, as it has no effect on our XOR operation. If we XOR the same numbers, it turns into 0. So, every pair...
ReadJuly 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
Valid sudoku
We can use 3 hashmap to store the values of rows, colums and square. For rows and columns hashmap we will use the row and column number as key. For square hashmap, we can use the integer division of...
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
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
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
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...
ReadJuly 10, 2022
Contains duplicate
We are given a list of integers. We have to find out whether we have any duplicate or not. We can store the elements in a hashset while iterating through the list. We the item is already present in...
Read