Problems


July 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...

Read

July 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...

Read

July 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...

Read

July 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...

Read

July 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....

Read

July 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...

Read

July 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...

Read

July 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...

Read

July 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

July 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
... 91 92 93 94 95