[Geeks for Geeks] X Total Shapes

X Total Shapes

Given a grid of n*m consisting of O’s and X’s. The task is to find the number of ‘X’ total shapes.

Note: ‘X’ shape consists of one or more adjacent X’s (diagonals not included).

Read more
[Geeks for Geeks] Container With Most Water

Container With Most Water

Given N non-negative integers a1,a2,….an where each represents a point at coordinate (i, ai). N vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i,0). Find two lines, which together with x-axis forms a container, such that it contains the most water.

Read more
[Geeks for Geeks] Is Sudoku Valid

Is Sudoku Valid

Given an incomplete Sudoku configuration in terms of a 9x9 2-D square matrix(mat[][]) the task to check if the current configuration is valid or not where a 0 represents an empty block.

Note: Current valid configuration does not ensure validity of the final solved sudoku.

Read more
[Geeks for Geeks] Prerequisite Tasks

Prerequisite Tasks

There are a total of N tasks, labeled from 0 to N-1. Some tasks may have prerequisites, for example to do task 0 you have to first complete task 1, which is expressed as a pair: [0, 1]
Given the total number of tasks N and a list of prerequisite pairs P, find if it is possible to finish all tasks.

Read more
[Geeks for Geeks] Minimum sum

Minimum sum

Given an array Arr of size N such that each element is from the range 0 to 9. Find the minimum possible sum of two numbers formed using the elements of the array. All digits in the given array must be used to form the two numbers.

Read more
[Geeks for Geeks] Wildcard Pattern Matching

Wildcard Pattern Matching

Given two strings ‘str’ and a wildcard pattern ‘pattern’ of length N and M respectively, You have to print ‘1’ if the wildcard pattern is matched with str else print ‘0’ .

The wildcard pattern can include the characters ? and *

  • ? – matches any single character
  • * – Matches any sequence of characters (including the empty sequence)

Note: The matching should cover the entire str (not partial str).

Read more
[Geeks for Geeks] Jump Game

Jump Game

Given an positive integer N and a list of N integers A[]. Each element in the array denotes the maximum length of jump you can cover. Find out if you can make it to the last index if you start at the first index of the list.

Read more
[Geeks for Geeks] Distinct occurrences

Distinct occurrences

Given two strings S and T of length n and m respectively. find count of distinct occurrences of T in S as a sub-sequence.

Read more
[Geeks for Geeks] Maximum sum of Non-adjacent nodes

Maximum sum of Non-adjacent nodes

Given a binary tree with a value associated with each node, we need to choose a subset of these nodes such that sum of chosen nodes is maximum under a constraint that no two chosen node in subset should be directly connected that is, if we have taken a node in our sum then we can’t take its any children or parents in consideration and vice versa.

Read more
[LeetCode] The Number of Good Subsets

1994. The Number of Good Subsets

You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.

  • For example, if nums = [1, 2, 3, 4]:
  • [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 23, 6 = 23, and 3 = 3 respectively.
  • [1, 4] and [4] are not good subsets with products 4 = 22 and 4 = 22 respectively.

Return the number of different good subsets in nums modulo 109 + 7.

A subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

Read more