[Geeks for Geeks] Overlapping Intervals

Overlapping Intervals

Given a collection of Intervals, the task is to merge all of the overlapping Intervals.

Read more
[Geeks for Geeks] Min cut Square

Min cut Square

Given two numbers M and N, which represents the length and breadth of a paper, the task is to cut the paper into squares of any size and find the minimum number of squares that can be cut from the paper.

Read more
[Geeks for Geeks] LRU Cache

LRU Cache

Design a data structure that works like a LRU Cache. Here cap denotes the capacity of the cache and Q denotes the number of queries. Query can be of two types:

  1. SET x y : sets the value of the key x with value y
  2. GET x : gets the key of x if present else returns -1.

The LRUCache class has two methods get() and set() which are defined as follows.

  1. get(key) : returns the value of the key if it already exists in the cache otherwise returns -1.
  2. set(key, value) : if the key is already present, update its value. If not present, add the key-value pair to the cache. If the cache reaches its capacity it should invalidate the least recently used item before inserting the new item.
  3. In the constructor of the class the capacity of the cache should be intitialized.
Read more
[Geeks for Geeks] Connect Nodes at Same LevelRead more
[Geeks for Geeks] Word Boggle

Word Boggle

Given a dictionary of distinct words and an M x N board where every cell has one character. Find all possible words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters

Note: While forming a word we can move to any of the 8 adjacent cells. A cell can be used only once in one word.

Read more
[Geeks for Geeks] Non Repeating Numbers

Non Repeating Numbers

Given an array A containing 2 x N+2 positive numbers, out of which 2 x N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers.

Read more
[Geeks for Geeks] Find median in a stream

Find median in a stream

Given an input stream of N integers. The task is to insert these numbers into a new stream and find the median of the stream formed by each insertion of X to the new stream.

Read more
[Geeks for Geeks] Maximum Index

Maximum Index

Given an array A[] of N positive integers. The task is to find the maximum of j - i subjected to the constraint of A[i] < A[j] and i < j.

Read more
[LeetCode] Smallest Range Covering Elements from K Lists

632. Smallest Range Covering Elements from K Lists

You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.

We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.

Read more
[LeetCode] Delete Duplicate Folders in System

1948. Delete Duplicate Folders in System

Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the ith folder in the file system.

  • For example, [“one”, “two”, “three”] represents the path “/one/two/three”.

Two folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.

  • For example, folders “/a” and “/b” in the file structure below are identical. They (as well as their subfolders) should all be marked:
  • /a
  • /a/x
  • /a/x/y
  • /a/z
  • /b
  • /b/x
  • /b/x/y
  • /b/z
  • However, if the file structure also included the path “/b/w”, then the folders “/a” and “/b” would not be identical. Note that “/a/x” and “/b/x” would still be considered identical even with the added folder.

Once all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.

Return the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.

Read more