[Geeks for Geeks] Travelling Salesman Problem

Travelling Salesman Problem

Given a matrix cost of size n where cost[i][j] denotes the cost of moving from city i to city j. Your task is to complete a tour from the city 0 (0 based index) to all other cities such that you visit each city atmost once and then at the end come back to city 0 in min cost.

Read more
[Geeks for Geeks] Hamiltonian Path

Hamiltonian Path

A Hamiltonian path, is a path in an undirected or directed graph that visits each vertex exactly once. Given an undirected graph the task is to check if a Hamiltonian path is present in it or not.

Read more
[Geeks for Geeks] Word Break - Part 2

Word Break - Part 2

Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences.

Follow examples for better understanding.

Read more
[Geeks for Geeks] Maximum absolute difference between sum of two contiguous sub-arrays

Maximum absolute difference between sum of two contiguous sub-arrays

Given an array of integers, find two non-overlapping contiguous sub-arrays such that the absolute difference between the sum of two sub-arrays is maximum.

Read more
[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