Select Copy Paste Problem 1 - Minimum operations

Problem There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step: Copy All: You can copy all the characters present on the screen (a partial copy is not allowed). Paste: You can paste the characters which are copied last time. Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen. ...

Subset Sum Problem 1 - Is there a subset?

Problem Given a list of integers S and a target number k, write a function that returns a true if there is subset of S that adds up to k. If such a subset cannot be made, then return false. Examples Example 1: nums = [2, 3, 5], k = 7 Output: true Explanation: Subset is [2, 5] ...

Word Break 2 - Construct a sentence

Problem Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note that the same word in the dictionary may be reused multiple times in the segmentation. Examples Example 1: Input: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"] Output: ["cats and dog","cat sand dog"] ...

Maximum Number of Points with Cost Problem

Problem You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix. To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score. However, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score. ...

Maximum Subarray Sum

Problem Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Examples Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. ...

Knight Probability in Chessboard Problem

Problem On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1). A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction. ...

Longest Increasing Subsequence LIS Problem

Problem Given an unsorted array of integers, find the length of longest increasing subsequence. Examples Example 1: Input: A = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. ...

Longest Common Subsequence LCS 1 - Get Length

Problem Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings. ...

Longest Common Subsequence LCS 2 - Get Subsequence

Problem Given two sequences, return the longest subsequence present in both of them. Examples Example 1: Input: text1 = "abcde", text2 = "ace" Output: "ace" Explanation: The longest common subsequence is "ace". Example 2: Input: text1 = "abc", text2 = "abc" Output: "abc" Explanation: The longest common subsequence is "abc". ...

Unique Paths in Grid - Count all paths moving right or down or diagonally

Problem There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right or diagonally at any point in time. Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy