Minimum Columns to Remove for Lexicographical Order in Matrix Problem

Problem You are given an N by M 2D matrix of lowercase letters. Determine the minimum number of columns that can be removed to ensure that each row is ordered from top to bottom lexicographically. That is, the letter at each column is lexicographically later as you go down each row. It does not matter whether each row itself is ordered lexicographically. For example, given the following table: ...

Maximum Distance in Arrays Problem

Problem You are given m arrays, where each array is sorted in ascending order. You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|. Return the maximum distance. Examples Example 1: Input: arrays = [ [1,2,3],[4,5],[1,2,3] ] Output: 4 Explanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array. ...

Regions Cut By Slashes Problem

Problem An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions. Given the grid grid represented as a string array, return the number of regions. Note that backslash characters are escaped, so a '\' is represented as '\\'. Examples Example 1: ...

Magic Squares In Grid Problem

Problem A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given a row x col grid of integers, how many 3 x 3 contiguous magic square subgrids are there? Note: while a magic square can only contain numbers from 1 to 9, grid may contain numbers up to 15. ...

Spiral Matrix 4 - From Linked List

Problem You are given two integers m and n, which represent the dimensions of a matrix. You are also given the head of a linked list of integers. Generate an m x n matrix that contains the integers in the linked list presented in spiral order (clockwise), starting from the top-left of the matrix. If there are remaining empty spaces, fill them with -1. Return the generated matrix. ...

Spiral Matrix 3 - Traverse from Given Starting Point

Problem You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column. You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid’s boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid. ...

Minimum Number of Pushes to Type Word 2 Problem

Problem Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" . It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word. ...

Determining the Existence of a Valid Secret Code in Mastermind Based on Given Guesses and Scores

Problem Mastermind is a two-player game in which the first player attempts to guess the secret code of the second. In this version, the code may be any six-digit number with all distinct digits. Each turn the first player guesses some number, and the second player responds by saying how many digits in this number correctly matched their location in the secret code. For example, if the secret code were 123456, then a guess of 175286 would score two, since 1 and 6 were correctly placed. ...

Range Sum of Sorted Subarray Sums Problem

Problem You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers. Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 10^9 + 7. ...

Minimum Swaps to Group All 1's Together 1 - In an array

Problem A swap is defined as taking two distinct positions in an array and swapping the values in them. Given a binary array nums, return the minimum number of swaps required to group all 1’s present in the array together at any location. Examples Example 1: Input: nums = [1,0,1,0,1] Output: 1 Explanation: There are 3 ways to group all 1's together: [1,{0},1,0,{1}] => [1,1,1,0,0] using 1 swap. [1,0,1,{0},{1}] => [{1},{0},1,1,0] => [0,1,1,1,0] using 1 swaps. [{1},0,1,{0},1] => [0,0,1,1,1] using 1 swap. The minimum is 1. ...

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