Problems


December 27, 2022

Perfect number

We will find all the divisors of the number and then sum them up. If the sum is equal to the number, then it is a perfect number. Time complexity: O(sqrt(n)) Space complexity:...

Read

December 27, 2022

Next palindrome using same digits

We will find the next permutation that is greater than the first half of the palindrome, say greaterHalf. Then add it to the mid item if there is one and to reversed of greaterHalf. Time...

Read

December 27, 2022

Synonymous sentences

We will create a graph where the nodes are the words and the edges are the synonyms. Then we will do a DFS to find all the possible sentences and add that to a hashset to remove duplicates. Finally,...

Read

December 27, 2022

Prefix and suffix search

We will generate all possible prefixes and suffixes for each word and store them in a hashmap. Then, we will iterate over the queries and return the maximum weight. Time complexity:...

Read

December 27, 2022

XOR operation in an array

We will generate the array and then XOR all the elements. Time complexity: O(n) Space complexity: O(1) We can also use reduce function to XOR all the...

Read

December 26, 2022

Shortest unsorted continuous subarray

We will sort the array and find the first and last index where the elements are different. Time complexity: O(nlog(n)) Space complexity: O(n)

Read

December 26, 2022

Bitwise or of all subsequence sums

We will iterate over the array and update the prefix sum and bitwise or of all subsequence sums. Time complexity: O(n) Space complexity: O(1)

Read

December 26, 2022

Out of boundary paths

We will solve the problem recursively. We will use a memo to store the number of paths from (i, j) to (m, n). Time complexity: O(mn) Space complexity:...

Read

December 25, 2022

Reward top k students

We will sort the students by their scores and then iterate over the students and reward them. Time complexity: O(nlog(n)) Space complexity: O(n)

Read

December 25, 2022

Most popular video creator

We will count the number of videos for each creator. Then we will iterate over the videos and count the number of views for each creator. We will update the result. Time complexity:...

Read
... 12 13 14 15 16 ...