Dataset Viewer
Auto-converted to Parquet Duplicate
messages
listlengths
1
1
[ { "content": "You are given a `m x n` 2D grid initialized with zeros. Use the following operations to change the values in the grid:\n\n1. `setUniformValue(r1, r2, c1, c2, value)` - sets all the cells in the subgrid from `(r1, c1)` to `(r2, c2)` to the specified `value`.\n2. `querySum(r1, r2, c1, c2)` - returns...
[ { "content": "You are given a list of positive integers `heights`, where each integer represents the height of a building. Each building is of uniform width `1`. You want to add water such that each building can hold water up to the height of the lowest neighboring buildings. Calculate the maximum amount of wat...
[ { "content": "Write a function `findSubstring` that takes in two strings, `s` and `words`. The `words` array is a list of strings, with all strings of the same length. Return all starting indices of substring(s) in `s` that is a concatenation of each word in `words` exactly once, in any order, and without any i...
[ { "content": "You are given a binary string `s` which consists only of characters '0' and '1'. Your goal is to find the length of the longest contiguous subarray that contains an equal number of '0's and '1's. Implement a function that returns this length. If no such subarray exists, return 0.", "role": "us...
[ { "content": "You are planning a hiking trip and want to prepare a nutritional meal plan. You have `n` food items, and each food item has a certain number of calories. You want to create a meal plan such that the total calorie intake is as close as possible to `targetCalories`. Given an array `foods` where `foo...
[ { "content": "You are given a **0-indexed** string `word`, consisting of lowercase English letters. You need to perform **cyclic shifts** on the string. A cyclic shift moves the last character of the string to the front, the second last character to the second position, and so forth. Given an integer `k`, retur...
[ { "content": "You are given a string `s` and an array of strings `dictionary`. The string `s` can be formed by inserting a certain number of characters (possibly zero) at any positions in each string `word` in `dictionary`. However, you can insert different characters at different positions for different words ...
[ { "content": "Given a string `s`, determine if it can be made a palindrome by removing at most one character. A string is a palindrome if it reads the same forward and backward.\n\nCompose a function `canFormPalindrome(s)` that takes a string `s` as its parameter and returns a boolean value indicating whether i...
[ { "content": "Given an array of integers `nums`, return the length of the longest subsequence that can be derived by deleting some or no elements such that the elements appear in **non-decreasing order**. Note that \"subsequence\" refers to a sequence obtained by deleting some or no elements without changing th...
[ { "content": "You are given a **0-indexed** integer array `nums`. In one operation, you can increment or decrement any element of `nums` by `1`. You want to make all the elements in `nums` equal. Return _the minimum number of operations needed to make all elements of_ `nums` _the same_.", "role": "user" }...
[ { "content": "You are given a **0-indexed** integer array `nums` and an integer `x`. Your goal is to find the smallest length of a subarray that has a sum greater than or equal to `x`. If there is no such subarray, return `-1`. A **subarray** is a contiguous part of the array. Additionally, you must accomplish ...
[ { "content": "You are given a list of strings `logs` where each string represents a log written by a user in the format `\"user_id action timestamp\"`. The `timestamp` is an integer representing the time when the action was taken. Each user can perform multiple actions, and the list is unsorted. Implement a fun...
[ { "content": "Given a `2D` grid of size `m x n` representing a map where `1` represents land and `0` represents water, you are also given an integer `k`. You want to determine the shortest distance in terms of step count to move from the top-left corner of the grid to the bottom-right corner, avoiding obstacles...
[ { "content": "You are given a 2D grid of characters `grid` where each character is either an obstacle (`'#'`) or a free cell (`'.'`). You can move up, down, left, or right, but you cannot move onto obstacles, and you cannot move outside the boundaries of the grid. You start at the cell located at the top-left c...
[ { "content": "You have a `friends` matrix representing a friendship graph, where `friends[i][j]` is 1 if person i and person j are friends, and 0 otherwise. A friend group is a group of people who are all directly or indirectly friends. Your task is to write a function that returns the number of friend groups i...
[ { "content": "You are given a **0-indexed** integer array `nums`, which contains `n` integers. You need to create a new array `result` where `result[i]` is equal to the product of all the elements of `nums` except `nums[i]`. For example, if `nums = [1, 2, 3, 4]`, then `result = [24, 12, 8, 6]`. Write a functio...
[ { "content": "Given a string `s` which represents a student’s answers to a test consisting of `n` binary questions (either '0' or '1'), and an integer `k` indicating the maximum allowed consecutive wrong answers ('0's), return the length of the longest contiguous subarray where the number of wrong answers does ...
[ { "content": "You are given an array of integers `nums` representing scores of different participants in a contest, and an integer `k` representing the number of winners to be selected. Winners are defined as participants with the highest scores, and in case of a tie, all tied participants are considered winner...
[ { "content": "You are given a string `s` and an integer `n`. Your task is to determine the minimum number of characters you need to delete from `s` to make it a valid string. A valid string is defined as a string that does not contain any character that appears more than `n` times. Return _the minimum number of...
[ { "content": "You are given a **0-indexed** array `nums` of integers. The array is said to be \"rotationally sorted\" if it can be transformed into a non-decreasing order sequence by performing a **cyclic rotation**. A cyclic rotation in this context means moving the elements of the array from the end to the fr...
[ { "content": "You work for a company that processes large datasets. You are given a list of integers `nums` representing dataset IDs, which may contain duplicates. Your task is to determine if any integer appears **at least three times** in the list. If such an integer exists, return `true`; otherwise, return `...
[ { "content": "You are given a list of non-negative integers `nums` and an integer `k`. Rearrange the elements of `nums` such that the difference between any two consecutive elements does not exceed `k`. If possible, return the rearranged list. If it is not possible, return an empty list.", "role": "user" ...
[ { "content": "You are given a **0-indexed** string `s` which consists of only lowercase English letters. You can perform the following operation any number of times: Choose any character and assign it a new value between 'a' and 'z' inclusively, which becomes its **new value** in the string. The goal is to make...
[ { "content": "You are given a sequence of integers where each integer appears exactly twice, except for one element that appears exactly once. Write a function to find the element that appears exactly once within the sequence. Your solution should have a linear runtime complexity and use only constant extra spa...
[ { "content": "You are given an array `arrival` representing the arrival times of trains at a station (in minutes from midnight) and an array `departure` representing the departure times of those trains. The task is to find the minimum number of platforms required at the station so that no train has to wait. Imp...
[ { "content": "You are given an integer array `nums` and an integer `target`. Your task is to determine if any two distinct elements from the array add up to the target. If there are such elements, return the indices of the two numbers. If there are no such elements, return an empty list. Note that each input wo...
[ { "content": "Given a string `s` which represents a **sentence** consisting of lowercase letters and spaces, and an integer array `words` where each element is the length of a word that should appear in the sentence. Each word in the `words` array must be separated by exactly one space. Return `true` if the sen...
[ { "content": "You are given an array of integers `arr` where `arr[i]` represents the height of plant `i` in a garden. You can perform the following operation as many times as necessary: choose two adjacent plants, and if their difference in height is greater than or equal to `d`, prune the taller plant to be ex...
[ { "content": "Given a binary tree, you need to serialize and deserialize it. Serialization is the process of converting a tree to a string representation so that it can be easily stored or transmitted, and deserialization is the process of converting the string representation back to the original tree structure...
[ { "content": "Given an integer array `nums`, determine if there exists a contiguous subarray whose sum is equal to a given integer `k`. If such a subarray exists, return `true`; otherwise, return `false`. Your solution should aim for an optimal time complexity.", "role": "user" } ]
[ { "content": "You are developing a task scheduler that manages the execution of tasks, each represented by a character (e.g., `'A'`, `'B'`, `'C'`, etc.). Some tasks need to be executed at fixed intervals or have a cooldown period such that the same task can't be executed again until a certain number of interval...
[ { "content": "Given an array `nums` of `n` integers, where `n` is even, you need to perform `n/2` operations. In each operation, you can choose two indices `i` and `j` (`0 <= i, j < n`, `i != j`) and remove the elements at `nums[i]` and `nums[j]` from the array. The cost of this operation is `nums[i] + nums[j]`...
[ { "content": "Given a string `s` consisting of lower-case English letters, divide it into as few parts as possible so that each letter appears in at most one part. Return _a list of integers representing the size of these parts_ in order of their appearance in the original string.", "role": "user" } ]
[ { "content": "You are given a binary tree where each node contains an integer value. Your task is to determine if the tree is a **height-balanced** binary tree. A height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Return `tru...
[ { "content": "You are given a text composed of lowercase and uppercase letters in a string `s`. You need to calculate the \"weight\" of this string. The weight of a string is defined as the sum of weights of all distinct characters multiplied by their respective frequencies. The weight of a character is the pos...
[ { "content": "You are given a 2D integer matrix `grid` of size `m x n` and an integer `threshold`. Each cell in the `grid` represents the elevation of a point within a region. A region is defined as a group of connected cells with elevation values greater or equal to `threshold`. Two cells are considered connec...
[ { "content": "Given an array of integers `arr` of length `n` and an integer `target`, return _the **length** of the **longest subarray** of `arr` the sum of whose elements equals_ `target`. If there is no such subarray, return `0`.", "role": "user" } ]
[ { "content": "Given an array of integers `nums`, return the **longest contiguous subarray** that contains only unique elements. If there are multiple such subarrays, return the one that occurs first. \n\nFor example:\n- Given `nums = [1, 2, 3, 1, 2, 3, 4, 5]`, the function should return `[1, 2, 3, 4, 5]`.\n- Gi...
[ { "content": "You are given a **0-indexed** integer array `nums` containing `n` positive integers where `n` is **even**. Your task is to partition the array into two subarrays `A` and `B` such that both subarrays are non-empty and their lengths are half of `n`. Return _the **minimum** possible absolute differen...
[ { "content": "You are given a list of pairs of dates represented as strings in the format \"YYYY-MM-DD\". Each pair represents a start date and an end date of a time interval inclusive. Write a function to determine the total number of unique days covered by all the given date intervals. If two or more interval...
[ { "content": "A factory produces widgets, and each widget is produced using `materials` represented by an array `costs`, where `costs[i]` is the cost of the `i-th` material. The factory also has multiple discount offers, each represented by an array `discounts` where `discounts[j] = [k, d]` provides a discount...
[ { "content": "You are given an integer array `heights` representing the heights of people standing in a queue. Implement a function to determine the minimum number of adjacent swaps necessary to sort the array in non-decreasing order of heights, where each swap can only involve elements that are in consecutive ...
[ { "content": "You are given a string `s` consisting of lowercase letters and an array of pairs of indices in the string where each pair `(a, b)` indicates that the characters at these indices can be swapped. You are allowed to swap the characters at the given indices any number of times to make the string as le...
[ { "content": "Given an integer array `arr` of size `n`, you need to find out if there are any duplicate elements within `k` distance of each other. In other words, check if there are two distinct indices `i` and `j` in the array such that `arr[i] == arr[j]` and the absolute difference between `i` and `j` is at ...
[ { "content": "You are given an integer array `arr`, where each element is distinct and sorted in ascending order. A **mountain array** is defined as an array that:\n\n- Has at least three elements.\n- There exists some `i` with `0 < i < arr.length - 1` such that:\n - `arr[0] < arr[1] < ... < arr[i]`\n - `arr[...
[ { "content": "You are given a 2D integer matrix `matrix` of size `m x n`. Your task is to count the number of cells that have at least one neighboring cell with a greater value than the current cell. Two cells are considered neighboring if they are adjacent horizontally, vertically, or diagonally. Implement a f...
[ { "content": "Given two strings `s` and `t`, your goal is to determine whether `s` can be transformed into `t` by applying one of the following operations exactly once:\n\n1. **Insert** one character anywhere in `s`.\n2. **Delete** one character from `s`.\n3. **Replace** one character in `s` with another charac...
[ { "content": "You are given a list of non-negative integers `nums`, and you are tasked to form a ring such that each integer in `nums` points to another integer, forming a circular chain. Determine if this ring configuration can be made **palindromic**. A palindromic ring means that reading the numbers in the r...
[ { "content": "Given an integer array `arr`, return _the length of the longest subarray with positive product_.", "role": "user" } ]
[ { "content": "You are given an array `buildings` where each element represents the height of a building. An ocean view is defined as a building that can see the ocean (i.e., there are no higher buildings to its right). Return an array of indices of these buildings in ascending order of their appearance in the `...
[ { "content": "You are given a `rows x cols` binary matrix filled with `0`s and `1`s. A **rectangle** is a portion of the matrix where all elements are `1`. A rectangle can have any size, but the width and height of the rectangle must be at least 1.\n\nImplement a function `maximalRectangle` that finds the **are...
[ { "content": "You are given a string `s` consisting of lowercase English letters, where a **run** is a sequence of consecutive repeating characters. Convert the string `s` into a compressed form by replacing each run with the character followed by the length of the run (if the run length is greater than 1). For...
[ { "content": "Consider a function that implements an algorithm to determine if a string `s` can be transformed into a palindrome by rearranging its characters. The function has one input parameter, `s`, which is a non-empty string consisting of lowercase English letters. The purpose of the function is to return...
[ { "content": "You are given a `k x k` binary matrix `matrix` and an integer `k`. A binary matrix is a matrix that has only `0`s and `1`s as its elements. Your task is to determine the length of the largest square that can be obtained by selecting a submatrix from `matrix` such that all of its elements are `1`. ...
[ { "content": "You are given an `n x n` grid containing integers. Each integer represents the height of a building located at that position in the grid. You are also given two pairs of coordinates `start` and `end`, each defined as `(row, column)`. The task is to find a path from `start` to `end` such that the m...
[ { "content": "Implement a function that takes a string `s` consisting of lowercase English letters. The function should return the number of palindromic substrings in `s`. A string is palindromic if it reads the same forward and backward. Note that the single-character substrings are palindromic by default.\n\n...
[ { "content": "You are given a non-empty `k`-array tree where each node contains a list of integers representing its children. Write a function to determine if the given tree is a **full** `k`-ary tree or not. A **full** `k`-ary tree is a tree where every node has exactly `k` children or is a leaf node (a node w...
[ { "content": "You are given a list of tasks represented by characters and an integer `n` representing the cooldown period between the same tasks. The objective is to find the minimum time required to complete all tasks. Each task takes 1 unit of time and must be performed one at a time. The cooldown period `n` ...
[ { "content": "You are given a **0-indexed** array of integers `nums` and an integer `target`. Your task is to form the largest possible **concatenated** string by choosing elements from `nums` such that their combined total is less than or equal to `target`. Each element can be used only once and their individu...
[ { "content": "A **pattern** is a string that consists of lowercase letters, where each letter represents a typed letter from the keyboard. Given a string `source` and a list of strings `patterns`, return a list of boolean values indicating, for each pattern, whether it is a subsequence of the `source` string. A...
[ { "content": "You are given an integer array `nums` containing `n` unique numbers in the range from `1` to `n`. The array may be shuffled and may contain any permutation of these numbers. Your task is to determine if it is possible to sort this array in ascending order by performing a series of operations. In o...
[ { "content": "Given a list of `n` integers representing daily stock prices, where `prices[i]` is the price of a given stock on day `i`, return the maximum profit you can achieve by buying and selling the stock with the following constraints: you may complete as many transactions as you like (i.e., buy one and s...
[ { "content": "Given a list `logs` of logged in and log-out times of different users represented as 2D integer vectors where `logs[i] = [userid, loginTime, logoutTime]`. Each log represents a user logging in at `loginTime` and logging out at `logoutTime`. A user is considered logged in for any duration between `...
[ { "content": "You are given a **string** `s` consisting of lowercase English letters. You need to group the characters of the string into **substrings** such that each letter appears in at most one substring. Additionally, a character should not appear in any other part of the string after its respective substr...
[ { "content": "Given a non-empty array of integers `nums`, every element appears twice except for one. Find that single one. Implement a function `findUnique(nums)` that returns the single one. Your algorithm should have a linear runtime complexity. Can you implement it without using any extra memory?", "rol...
[ { "content": "Given an array of integers `nums`, where each `nums[i]` represents the price of a stock on the `i-th` day, your task is to determine the maximum profit you could achieve if you were allowed to complete **at most one transaction**. A transaction is defined as buying one share of the stock and selli...
[ { "content": "Given an array `nums` consisting of distinct integers, return _a length of the longest sequence of consecutive numbers that can be found in `nums`_.", "role": "user" } ]
[ { "content": "Given a directed acyclic graph (DAG) with `n` nodes labeled from `0` to `n-1`, and a list of edges where `edges[i] = [fromi, toi]` representing a directed edge from `fromi` to `toi`, return _a boolean indicating whether the graph contains a valid topological ordering_. A topological ordering is va...
[ { "content": "Implement a function that takes two strings `pattern` and `str`. Determine if `str` follows the same pattern as defined by `pattern`. Here, 'follows' means a **bijective** mapping (i.e., a one-to-one correspondence) between characters in `pattern` and non-empty words in `str`. \n\nFor example:\n\n...
[ { "content": "You are given a string `s` consisting of lowercase English letters, and an integer `limit`. Your task is to find the length of the longest substring of `s` such that the number of distinct characters in the substring does not exceed `limit`. Return the length of the longest substring.\n\nExample:\...
[ { "content": "Given an array of integers `nums` representing a contiguous subarray of length `n` of an infinite array formed by repeating the elements of `nums` infinitely, return _the maximum sum of any subarray of length `n` of this infinite array_. If the array is empty, return 0. For example, given `nums =...
[ { "content": "You are given a string `s` and an array `indices` of the same length where `indices[i]` represents the index in the final string where the character at `s[i]` should go. Reconstruct the string by rearranging the characters according to the given `indices` array. Return the reconstructed string.", ...
[ { "content": "You are given a **0-indexed** binary array `nums`, where a `1` represents a person standing and a `0` represents an empty space. Your task is to find the maximum distance between any two standing persons such that no other person is standing between them. If there are less than two standing person...
[ { "content": "You are given two integer arrays `startTime` and `endTime`, and an integer array `profit` where `startTime[i]`, `endTime[i]`, and `profit[i]` denote the start time, end time, and profit of the `i-th` job respectively.\n\nYou are also given an integer `maxEndTime`, which denotes the maximum end tim...
[ { "content": "You are given a **0-indexed** integer array `nums` and an integer `target`. You need to determine if there exist three numbers in `nums` whose sum is equal to `target`. Return `true` if such a triplet exists, otherwise return `false`.\n\nFor example, given `nums = [1, 2, 3, 4, 5]` and `target = 9`...
[ { "content": "Given a 2D matrix `grid` of integers, where each element represents the height of a block, determine the surface area of the 3D shape formed by these blocks. The shape created by stacking the blocks on top of each other is such that it completely fills the grid. You need to calculate the total sur...
[ { "content": "You are given an integer array `height` of length `n` representing the height of buildings in a row. Each building `i` is represented by a vertical line drawn from the point `(i, 0)` to `(i, height[i])`. The width of each building is `1`. A rainwater trapping system has just been installed, and th...
[ { "content": "Given an integer array `arr` of size `n`, return a new array `result` where `result[i]` is equal to the **sum** of all the **unique** elements in `arr` except `arr[i]`. If the array is empty, return an empty array. For example, if `arr` is `[1, 2, 3, 2]`, the `result` should be `[5, 4, 3, 4]` beca...
[ { "content": "Given a string `s` consisting only of digits, return the largest **even** number that can be formed by rearranging the digits. If no even number can be formed, return an empty string.", "role": "user" } ]
[ { "content": "You are given an array of integers `arr` and a positive integer `k`. Your task is to modify the array by either incrementing or keeping any single element unchanged. The increment operation can be performed any number of times, but each operation has a cost of 1. You need to make all elements in t...
[ { "content": "You are given a string `s` consisting of lowercase English letters. You need to find the longest substring containing only unique characters and return its length. If the string is empty, return 0. Your task is to implement a function that executes this requirement efficiently.", "role": "user...
[ { "content": "You are given an m x n matrix filled with integers. Your task is to count the number of distinct paths from the top-left cell to the bottom-right cell of the matrix such that the sum of the integers along the path is equal to a given integer `target`. You can only move right or down from a cell. R...
[ { "content": "You are given two binary strings `a` and `b`. Your task is to add these binary strings and return their sum as a binary string. The input strings are non-empty and contain only characters `1` or `0`. The result should also be a binary string.", "role": "user" } ]
[ { "content": "You are given a string `s` containing only lowercase letters and an integer `n`. Your task is to determine the number of distinct substrings of length `n` that appear more than once in the string `s`. Return _the number of such substrings_.", "role": "user" } ]
[ { "content": "You are given an integer array `nums` and an integer `k`. A **continuous subarray** is defined as a subarray where the difference between the maximum and minimum values is at most `k`. Return _the length of the longest continuous subarray that meets this condition in_ `nums`. **Note:** A subarray...
[ { "content": "A group of friends is planning a trip and wants to rent cars to get around. There are `k` types of cars available, and each type `j` can hold `capacity[j]` persons. The group consists of `n` people and they want to fit exactly `n` people in the rented cars. Each car can be rented multiple times.\n...
[ { "content": "You are organizing an art gallery exhibit which opens at `09:00` AM and closes at `06:00` PM every day. You are given several booking requests formatted as strings with the start and end times of each booking. Each booking request is represented by a pair of 24-hour formatted times (e.g., \"13:00-...
[ { "content": "Given a **sorted** array of integers `arr` and an integer `x`, find _the pair of integers in the array whose difference is equal to_ `x`. _If there are multiple such pairs, return **any** one of them. If no such pair exists, return an **empty** pair._ The integers in the pair should appear in asce...
[ { "content": "You are given a string `s`, which may contain letters and digits. Write a function to reformat the string so that the letters and digits alternate, starting with a letter if there are at least as many letters as digits, and otherwise starting with a digit. If it is not possible to reformat the str...
[ { "content": "You are given an m x n matrix `board` containing characters `'X'` and `'O'`, where `'X'` represents a captured region and `'O'` represents an uncaptured region. Capture all regions that are 4-directionally surrounded by `'X'`. A region is captured when `'O'` is surrounded by `'X'` on all four side...
[ { "content": "Given an `m x n` grid `grid` of integers, a **path** from the top-left to the bottom-right corner is any sequence of cells such that you only move down or right at any point in time. The **minimum path sum** from top-left to bottom-right is the sum of the values of the cells along the path. Write ...
[ { "content": "You are given two strings, `str1` and `str2`. Your task is to determine if `str1` can be rearranged to form `str2`. In other words, check if the two strings are anagrams of each other. An anagram of a string is the rearrangement of its characters to form another string using all the original chara...
[ { "content": "In a game, you are given a list of integers representing the power levels of wizards. You are also provided with a target integer `S`, which represents a specific power level sum you need to achieve using consecutive wizards. Write a function that determines whether there exists a contiguous subar...
[ { "content": "Write a function that takes a 2D list `grid` representing a grid of integers and returns the maximum sum of elements in any single row or column. The function should make use of efficient traversals to ensure a minimal runtime. The grid can have different numbers of rows and columns, but every ele...
[ { "content": "Write a function `rotateMatrix` that receives an `n x n` 2D matrix representing an image as an input and rotates the image by 90 degrees (clockwise). You need to modify the input matrix **in-place**. The rotation should be done directly on the matrix provided, without using another matrix.\n\nTo r...
[ { "content": "You are given an array of positive integers `nums` and an integer `x`. You can decrease or increase each element in `nums` by at most `x` units. Determine if it is possible to make all elements in the array equal after performing the allowed modifications. Return `true` if it is possible, or `fals...
[ { "content": "You are given a list of integers `nums` representing the number of apples on each of `n` consecutive days. You can pick apples only once per day and must wait at least `k` days before picking apples again. Return the maximum number of apples you can pick over the `n` days.", "role": "user" }...
[ { "content": "Given an array of integers, sort the array in ascending order using the heap sort algorithm. You should not use any built-in sort functions or libraries. Output the sorted array.", "role": "user" } ]
[ { "content": "Given a list of strings `words`, each string `words[i]` contains only lowercase letters. A string `b` is a **subsequence** of a string `a` if `b` can be obtained from `a` by deleting some (possibly zero) characters of `a`. You need to find the longest string in `words` that can be formed by deleti...
[ { "content": "You are given an integer array `nums` and an integer `k`. We call an array beautiful if it satisfies the following two conditions: \n1. Every index `i` in `nums` has at most `k` positions containing an element equal to `nums[i]` to its left (including `i` itself).\n2. Every index `i` in `nums` has...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
6