messages listlengths 1 1 |
|---|
[
{
"content": "You are given a list of `tickets` where each ticket represents a journey from one city to another city [from, to]. You need to reconstruct the itinerary in order and return it. All the tickets form a valid itinerary. Start at \"JFK\" airport and follow the lexicographically smallest route when the... |
[
{
"content": "Given an array `nums` of size `n`, return _the maximum sum of any contiguous subarray of length `k`_. If there is no subarray of length `k`, return `0`. The input length will satisfy \\(1 \\leq k \\leq n \\leq 10^5\\) and \\(-10^4 \\leq nums[i] \\leq 10^4\\) for \\(0 \\leq i < n\\).",
"role": ... |
[
{
"content": "You are given a string `s` containing only lowercase English letters. A substring is called a \"good substring\" if there are no repeated characters within the substring. Your task is to find the length of the longest \"good substring\" that can be made from `s`. Implement a function that takes `s... |
[
{
"content": "You are given a `m x n` grid consisting of cells with non-negative integers. You are initially positioned at the top-left cell (0,0). You are allowed to move down, left, right, or up only if the value in the next cell you move to is greater than the value in the current cell. Determine if there is... |
[
{
"content": "Given an array of integers `nums` representing the number of coins in each pile, and an integer `k` representing the total number of coins you are allowed to remove, return the minimum possible total number of coins remaining in the piles after `k` coins have been removed. You may choose to remove... |
[
{
"content": "**[Question 4]:** Given an array of integers and an integer `k`, return `true` if there are two distinct indices `i` and `j` in the array such that `nums[i]` is equal to `nums[j]` and the absolute difference between `i` and `j` is at most `k`. Otherwise, return `false`.",
"role": "user"
}
] |
[
{
"content": "Given an array of integers `arr`, write a function that returns the length of the longest subarray that contains at most two distinct numbers. A subarray is a contiguous part of an array. The input array must contain at least one element and you should maximize the length of the subarray.\n\n**Exa... |
[
{
"content": "Given a matrix `mat` of size `n x m` where each cell contains an integer. You can perform operations on the matrix to maximize the sum of elements in the matrix after a series of transformations. The allowed operations are:\n* Swap the contents of any two cells.\n* Increment the value of any cell ... |
[
{
"content": "A company has a list of `n` projects labeled from `0` to `n-1`. Each project can have zero or more dependencies represented as a list of pairs `[a, b]` where project `a` must be completed before project `b` can begin. Write a function to determine if it is possible to complete all the projects giv... |
[
{
"content": "You are given a list of non-negative integers representing the heights of a set of bars. Your task is to determine how much water can be trapped after raining. The width of each bar is `1`. For instance, given the list `heights = [4,2,0,3,2,5]`, you can trap `9` units of water.\n\nWrite a function... |
[
{
"content": "You are given a list of integers representing the heights of buildings in a cityscape where the width of each building is 1. It is raining, and you need to determine how much water can be trapped between the buildings after it rains. Implement a function `trapRainWater(int[] height)` that returns ... |
[
{
"content": "Given a string `s` containing only lowercase letters, find and return the first non-repeating character in `s`. If all characters are repeating, return '_'.",
"role": "user"
}
] |
[
{
"content": "You are given a **0-indexed** integer array `heights` representing the height of students standing in a line. Each student `i` can see the student immediately in front of them if `heights[i] < heights[i+1]`. Write an algorithm to calculate the number of students who can see the student immediately... |
[
{
"content": "You are given a string `s` consisting of lowercase English letters, and an integer `k`. Your task is to remove exactly `k` characters from the string such that the resultant string has the **maximum** possible number of distinct characters. Return _the length of the resultant string_.",
"role"... |
[
{
"content": "You are implementing a text editor that supports the following operations: inserting a character, deleting the most recently inserted character, and retrieving the current text. Implement the `TextEditor` class with the following methods:\n- `TextEditor()` constructs a new text editor instance wit... |
[
{
"content": "Given a string `s` consisting of only alphabetic characters and spaces, return a new string where the characters appear in reverse order but the positions of spaces remain unchanged. Ensure lowercase and uppercase letters are maintained in their original form (e.g., 'a' remains 'a' and 'A' remains... |
[
{
"content": "You are given a list of strings `words` and a string `target`. Each string in `words` contains only lowercase English letters. You need to determine if you can form the `target` string by concatenating any number of strings (including zero) from the `words` list, where each string can be used only... |
[
{
"content": "You are given a string `s` that consists of lowercase alphabets and a 2D array `pairs` where each element `[a, b]` indicates that the characters at indices `a` and `b` in the string can be swapped. You need to return the lexicographically smallest string that can be formed by making any number of ... |
[
{
"content": "You are given a string `s` that represents a sentence containing words separated by exactly one space. Each word consists of lowercase English letters only.\n\nYour task is to move the first character of each word to the end of the word and then add \"ay\" to the end of the word. Return a single s... |
[
{
"content": "Given an array of integers `arr`, find the maximum length of a subarray that contains only even numbers. Return the _maximum length if such a subarray exists_, otherwise return `0`.",
"role": "user"
}
] |
[
{
"content": "You are given a 2D grid representing a park, where each cell is either empty (represented by `0`) or contains a tree (represented by `1`). You need to find the **smallest rectangle** that encloses all the trees and return the coordinates of this rectangle. The rectangle is defined by its top-left ... |
[
{
"content": "Given two integers `a` and `b`, return the smallest **positive integer** that is a multiple of both `a` and `b`. If the smallest multiple does not exist within a reasonable range (i.e., if either `a` or `b` is non-positive), return `-1`.",
"role": "user"
}
] |
[
{
"content": "A DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. Sometimes, due to errors in sequencing, random mutations happen. Given a DNA string `sequence`, and an integer `k`, determine the maximum number of times any substring of length `k` appears in the given se... |
[
{
"content": "You are given a string `s` consisting of only lowercase English letters. You can perform the following operation on `s` as many times as you want: Choose any character that appears at least twice in the string and remove all its occurrences. Return the length of the shortest string that can be obt... |
[
{
"content": "You are given an integer array `heights` representing the heights of a series of buildings. You are playing a game where you can increase the height of any building by 1 in each move. Your goal is to make all buildings' heights equal. Return the minimum number of moves required to make all the bui... |
[
{
"content": "Write a function that takes a list of non-negative integers representing the amount of rainwater at different elevations on a terrain. The function should compute the maximum amount of rainwater that can be trapped between the elevations after raining. Return the maximum amount of water that can b... |
[
{
"content": "You are given a list of `n` houses positioned along a straight road, represented by a **0-indexed** integer array `houses` where `houses[i]` is the position of the `i-th` house. You need to place `m` mailboxes along the road to minimize the total distance between each house and its nearest mailbox... |
[
{
"content": "Max is hosting a dinner party and wants to ensure that there are enough unique dishes for his guests. He has a list of `dishes` of length `m`, where each dish is represented by its name in a string. Max wants to find the maximum number of unique dishes he can prepare from the list, but he also kno... |
[
{
"content": "You are given a string `s` and an array of strings `words`. Your task is to determine for each word in `words` if it is a subsequence of `s`. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. ... |
[
{
"content": "Given a list of strings `words` and a string `target`, write a function to determine if `target` can be constructed by concatenating elements of the list `words` (elements can be reused). Return a boolean value indicating whether the target string can be formed.\n\nExample:\n- Input: `words = [\"a... |
[
{
"content": "You are given a string `s` and an integer `k`. You need to split the string into `k` parts such that each part is as even as possible in length. If the string cannot be evenly divided, some parts will be longer than others. Return a list of strings representing the split parts. If it is not possib... |
[
{
"content": "Given a string `s` containing only lowercase alphabet characters, return _a list containing the starting indices of all anagrams of a given string `p` within `s`_. An anagram is a permutation of a word, meaning all the characters of the word are present in the same frequency. For example, if `p = ... |
[
{
"content": "You are given an array of integers `nums` where the values can be both positive and negative. Your task is to find the **maximum product** of a contiguous subarray within the given array. A contiguous subarray is defined as a sequence of `nums` values with indices `i` and `j` such that `i <= j` an... |
[
{
"content": "Given a rectangular `matrix` of dimensions `m x n`, please write an algorithm to find a path from the top-left cell (0, 0) to the bottom-right cell (m-1, n-1) such that the sum of all integers along the path is minimized. You can only move either down or right at any point in time. The function sh... |
[
{
"content": "You are given an array of integers `nums`, where each integer appears either once or twice. Your task is to find all the integers that appear twice. Return the integers as an array in ascending order. Your solution should have a time complexity of O(n).",
"role": "user"
}
] |
[
{
"content": "You are given a list of integers `arr` representing the `heights` of buildings where `arr[i]` is the height of the `ith` building. The buildings are situated in a straight line and form a skyline from left to right. A building can be seen if and only if there are no taller buildings to its left th... |
[
{
"content": "You are given a list of strings `words`. A string is considered a **subsequence** of another string if it can be derived from the other string by deleting some or no characters without changing the order of the remaining characters. Return _an integer_ indicating the **length of the longest string... |
[
{
"content": "Given an unsorted array of integers, return an array of the same length where each element is replaced with the smallest element from the original array that is larger than the current element. If there is no such element, replace it with `-1`. The replacement should be done in O(n log n) time com... |
[
{
"content": "You are given a string `s` and an array of strings `dictionary`. Your task is to replace words in the string that are present in the dictionary with a character `#`. A word is defined as a sequence of non-space characters. _Return the modified string_ after all the replacements have been made.",
... |
[
{
"content": "You are given a string `formula` representing a chemical formula, which consists of lowercase letters, uppercase letters, and digits. The formula follows standard chemical notation, where an uppercase letter begins an element's symbol, which may optionally follow with a lowercase letter. A number ... |
[
{
"content": "Given an array `arr` of integers, you are tasked with determining whether it can be transformed into a non-decreasing array by modifying at most one element. Non-decreasing means that for every `i` (1 <= i < arr.length), `arr[i - 1] <= arr[i]`. \n\nReturn a boolean value `true` if the array can be... |
[
{
"content": "Given an array of integers `arr`, where every element is present an even number of times except for one element which is present an odd number of times. Find and return the element that is present an odd number of times. You must solve the problem with a linear runtime complexity and constant addi... |
[
{
"content": "You are given a string `s` and an array of strings `words`. All the strings in `words` are of the same length. A **concatenated sublist** is a string that is formed by concatenating all the strings in `words` exactly once, in any order. Your task is to find all the starting indices of the `s`'s su... |
[
{
"content": "You are given a rectangular grid with `m` rows and `n` columns, represented as a matrix where each cell contains an integer representing the height of the terrain at that cell. The task is to find the minimum height needed to cut through to ensure water flow from the top-left corner to the bottom-... |
[
{
"content": "You are given a binary string `s`, which consists of characters '0' and '1' only. You are allowed to flip at most one '0' to '1'. If you choose to make this flip, return the length of the longest contiguous sequence of '1's that can be achieved. If you don't need to make any flips, return the leng... |
[
{
"content": "You are given an array of integers `nums` representing the amount of money of each house, and another non-negative integer `k`. You are a thief planning to rob houses, but you cannot rob two adjacent houses. Design an algorithm to maximize the total amount of money you can rob, considering that af... |
[
{
"content": "You are given an integer array `numbers` and an integer `target`. You need to find all pairs of integers in the array whose sum is equal to `target`. Each pair should be represented as a tuple `(a, b)` where `a` and `b` are elements from the array and `a <= b`. Return a list of all such pairs `(a,... |
[
{
"content": "You are given a **0-indexed** integer array `cost` representing the cost of picking each candy from a row of candies, where `cost[i]` is the cost of picking the `i`th candy. You can pick any two candies such that the total cost does not exceed a given integer `budget`. Return _the maximum number o... |
[
{
"content": "You are working on a text editor application that supports a special undo feature. The application needs to keep track of the text entered by the user and support undo operations. Implement a class `TextEditor` with the following functionalities:\n\n- `TextEditor()`: Initializes the text editor wi... |
[
{
"content": "You are given an array of integers representing the heights of candle on a cake. Each candle can only be blown out if its height is not greater than the height of the previous candle you blew out. You can start blowing out any one candle. Return the maximum number of candles you can blow out conse... |
[
{
"content": "You are given two integer arrays `arr1` and `arr2` of sizes `m` and `n` respectively. Your task is to determine if they have the same set of elements, accounting for their frequencies. Specifically, you need to return `true` if `arr1` and `arr2` are permutations of each other (i.e., each unique el... |
[
{
"content": "You are given a list of integers `arr`. A sublist `sub` of `arr` is called a **strictly increasing subsequence** (SIS) if the elements of `sub` are in strictly increasing order.\n\nWrite a function that finds the length of the longest strictly increasing subsequence of `arr`.\n\nFor example, given... |
[
{
"content": "You are given a 2D grid `grid` of size `m x n` representing a field. Each cell in the grid contains either an obstacle represented by a `1` or empty space represented by a `0`. You start at the top-left corner of the grid (position `(0, 0)`) and your goal is to reach the bottom-right corner (posit... |
[
{
"content": "You are given two integers `a` and `b`, and you need to find the sum of all prime numbers between `a` and `b` (both inclusive). Write a function that accepts two integers as input and returns the sum of the prime numbers within the given range.\n\nFor example, if the input integers are `a = 10` an... |
[
{
"content": "You are given an array of strings `words` where each word consists of lowercase English letters. Your task is to find the longest chain of words in which every word is a **predecessor** of the next word in the chain. A word `wordA` is a predecessor of another word `wordB` if and only if `wordB` ca... |
[
{
"content": "You are given a string `s` and an integer `k`. The string `s` represents a ciphertext, and your task is to decrypt the ciphertext using a Caesar cipher with a right shift of `k`. The Caesar cipher shifts each letter in the string by `k` positions in the alphabet while wrapping around if necessary.... |
[
{
"content": "Given a list of integers, `arr`, determine whether it is possible to split `arr` into two subsequences such that the sum of the elements in each subsequence is equal. Return `true` if it is possible, and `false` otherwise. A **subsequence** is derived by deleting some or no elements from an array ... |
[
{
"content": "You are given a matrix `grid` of integers where each integer represents a different elevation. You are also given an array `path` of integers where each integer represents a specific elevation. Your task is to verify if there exists a path in the grid that matches the given path of elevations. \n\... |
[
{
"content": "You are given a 2D list `grid` of size `m x n` representing a maze where `1` represents walls and `0` represents open paths. Determine if there is a path from the top-left corner of the maze `(0, 0)` to the bottom-right corner `(m-1, n-1)`. You can only move up, down, left, or right. Return `true`... |
[
{
"content": "You are given a sequence of integers `arr` (of potentially arbitrary length) and an integer `k`. You need to determine if there is a subset of `arr` whose sum is exactly `k`. Return `true` if such a subset exists, otherwise return `false`.",
"role": "user"
}
] |
[
{
"content": "You are given an array of integers `heights` representing the heights of different buildings, and an integer `stones` representing the number of stones you can use to increase the height of any building. Each stone can increase the height of a building by exactly 1 unit. Your goal is to equalize t... |
[
{
"content": "Write a function that takes a string representing a mathematical expression in Reverse Polish notation (RPN) and evaluates it. Valid operators are `+`, `-`, `*`, and `/`. Each operand may be an integer or another expression. The division between two integers should truncate toward zero. It is guar... |
[
{
"content": "Given a grid of size `n x n` filled with positive integers, you are allowed to move either right or down from any cell, starting from the top-left corner. Write a function to find the minimum path sum from the top-left corner to the bottom-right corner of the grid. Return the minimum path sum.",
... |
[
{
"content": "Given a string `s`, determine the minimum number of steps required to make the string palindrome. In one step, you can change any character to any other character. Return the minimum number of steps.",
"role": "user"
}
] |
[
{
"content": "Design a function that, given a list of intervals representing a set of events, merges all overlapping intervals and returns a list of the merged intervals. Each interval is represented as a tuple `(start, end)`, where `start` and `end` are integers. The given intervals are not necessarily sorted.... |
[
{
"content": "You are given a **rotated sorted array** of unique elements, where the array was originally sorted in ascending order but then some number of positions were shifted to the right. You are also given a target value to search. Write a function to find the index of the target value in the rotated arra... |
[
{
"content": "You are given a grid representing a city, where each cell in the grid contains a non-negative integer indicating the cost to pass through that cell. You are to find a path from the top-left corner of the grid to the bottom-right corner such that the total cost is minimized. You can move in all fou... |
[
{
"content": "Given an array of integers `arr` and an integer `target`, you need to find if there exists a pair of integers in the array whose sum is equal to `target`. Return a list of the indices of the two numbers such that they add up to `target`. If such a pair does not exist, return an empty list.\n\n* Fo... |
[
{
"content": "You are given an integer array `arr` and an integer `k`. If the length of the array is less than `k`, return an empty array. Otherwise, return _an array of all possible **contiguous subarrays** of length `k`_. Each subarray should appear in **the order they appear in the original array**.",
"r... |
[
{
"content": "You are given an integer `n` representing the number of nodes in a graph labeled from `0` to `n-1`. You are also given a 2D integer array `edges` where `edges[i] = [node1, node2]` represents an undirected edge connecting two nodes in the graph. Write a function `maxConnectedComponents(n, edges)` t... |
[
{
"content": "Given a list of `n` integers, return all unique triplets in the list that sum up to zero. Each triplet in the output must be sorted in ascending order, and the output must not contain duplicate triplets. The function should return a list of lists, where each inner list is the triplet of integers t... |
[
{
"content": "You are given an array `edges` where `edges[i] = [a, b]` indicates there is an undirected edge between nodes `a` and `b` in a graph. Given an integer `n` representing the number of nodes in the graph labeled from `0` to `n-1`, return _the number of **connected components** in the graph_. \n\nA **c... |
[
{
"content": "You are given a list of words `words` and a pattern `pattern`. You need to find all the words in `words` that match the given `pattern`. A word matches the pattern if there exists a bijective mapping between characters in the word and characters in the pattern such that every character in the patt... |
[
{
"content": "You are given an array `candies` where `candies[i]` represents the number of candies in the `i-th` pile. You can perform the following operation any number of times (possibly zero): choose any pile of candies and discard half (rounded down) of the candies in that pile. For example, if there are `9... |
[
{
"content": "Given an array `arr` of integers where every integer appears an even number of times except for exactly **two** integers which appear an odd number of times, return _the two integers that appear an odd number of times_. The result should be in ascending order. You should implement your solution in... |
[
{
"content": "You are given a **0-indexed** integer array `nums` and an integer `threshold`. You need to find a **positive integer divisor** `d` such that, when every element in the array is divided by `d` and rounded up to the nearest integer, the sum of those resulting values is less than or equal to `thresho... |
[
{
"content": "Given a **0-indexed** array `arr` of integers, your task is to find the **minimum** number of operations required to make `arr` non-decreasing. In one operation, you can increment the value of any element in `arr` by `1`. An array is considered non-decreasing if for all `i` such that `0 <= i < arr... |
[
{
"content": "You are given a string `s` and an array of strings `patterns`. Each element in `patterns` represents a \"*wildcard*\" pattern where `?` can match any single character, and `*` can match any sequence of characters (including an empty sequence). Write a function that returns the number of patterns t... |
[
{
"content": "Given an integer array `arr`, find _the length of the longest subarray with an equal number of_ `0`s _and_ `1`s_.",
"role": "user"
}
] |
[
{
"content": "A software developer needs to process a log of transactions that contains different types of operations with varying levels of impacts on system resources. Each entry in the log is represented by an integer value, where positive integers indicate an increase in a specific resource, and negative in... |
[
{
"content": "You are given a 2D integer array `matrix` and an integer `k`. The 2D array represents a grid of integers. You need to find the maximum sum of any submatrix that contains exactly `k` elements. A submatrix is any contiguous block of elements within the matrix. Return the maximum sum of such a submat... |
[
{
"content": "You are given two non-empty strings `word1` and `word2` consisting of lowercase letters. You need to find the length of the longest subsequence that can be derived from both strings `word1` and `word2`. A subsequence is derived by deleting some or no characters of a string without changing the ord... |
[
{
"content": "You are given a string, `s`, which consists of only lowercase letters, and an array, `dict`, of unique strings, each also consisting of only lowercase letters. You need to determine the minimum number of transformations required to change the string, `s`, into one of the strings in `dict`. A trans... |
[
{
"content": "Given an integer array `heights` representing the heights of students in a line, where each student is standing in line from left to right. A student `i` can see another student `j` to their right if `heights[i] > heights[j]` (strictly taller). Return the number of students in the line who are abl... |
[
{
"content": "You are given an array of integers `arr` and an integer `threshold`. You need to determine if it is possible to split `arr` into two non-empty subarrays such that the sum of the elements in each subarray is greater than `threshold`. Return `true` if it is possible, and `false` otherwise.",
"ro... |
[
{
"content": "You are given an integer `amount` and an array of integers `coins` representing the available denominations of coins. Write a function to compute the number of combinations that make up that amount. You may assume that you have an infinite number of each kind of coin. Return the number of combinat... |
[
{
"content": "Given a **0-indexed** integer array `arr` and an integer `k`, you need to determine 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 most `k`. Return `true` if such indices exist, and `false` otherwise.",
... |
[
{
"content": "You are given a sorted array of distinct integers `arr` and a target value `target`. Write a function that finds the index of the first occurrence of `target` in `arr`. If `target` is not present in `arr`, return `-1`. The solution should aim to achieve a time complexity better than O(n).\n\nExamp... |
[
{
"content": "You are given two strings `s` and `t` consisting of lower-case English letters only. You want to make `t` an anagram of `s` by rearranging its letters. However, you can also change any letter of `t` to any other lower-case letter. Return _the **minimum** number of changes needed to make_ `t` _an a... |
[
{
"content": "Given a string `s` consisting of lowercase alphabets, return a list of all the distinct permutations of the characters in the string. The permutations in the list should appear in lexicographical order.\n\n---",
"role": "user"
}
] |
[
{
"content": "A company is developing a new calendar application and needs a functionality to manage event scheduling. Each event has a start time and end time, and the application should be able to handle overlapping events without conflicts. \n\nDesign a class `MyCalendar` to implement the following methods:\... |
[
{
"content": "Given an array of integers `arr` and an integer `k`, determine if the array can be partitioned into exactly `k` non-empty subsequences such that each subsequence contains numbers that are strictly increasing. Return `true` if such a partition is possible, otherwise return `false`.",
"role": "u... |
[
{
"content": "You are given a 2D integer array `flights` where `flights[i] = [departurei, arrivali]` indicates that there is a one-way flight from city `departurei` to city `arrivali`. You are also given a positive integer `k` representing the maximum number of flights you are willing to take. Return _the minim... |
[
{
"content": "You are tasked with designing a synchronous messaging application for a small group of users. The application uses an array of strings `messages`, where each string represents a message sent by one of the users. Each message is sent in chronological order. However, due to network delays, some mess... |
[
{
"content": "You are given a list of networks, where each network is represented by an adjacency list of its nodes. Your task is to identify the number of isolated networks. An isolated network is a set of nodes with no connections to any nodes outside their set. Each node is represented as an integer, and an ... |
[
{
"content": "You are given an array `queries` where `queries[i]` is a non-negative integer representing the number of seconds you need to wait for the `i-th` task to be completed. You also have an array `t` where `t[i]` is the number of seconds required to complete the `i-th` task. For each task `i`, if `queri... |
[
{
"content": "Given a matrix `mat` containing integers where each row is sorted in ascending order from left to right and each column is sorted in ascending order from top to bottom, write a function that searches for a target integer `x` and returns a tuple of its coordinates (row, column) if `x` is found. If ... |
[
{
"content": "Given a string `s` and a string `t`, your task is to find the minimum window in `s` which contains all the characters from `t`. If such a window does not exist, return an empty string. If there are multiple minimal windows, return the one which starts first. \n\nNote that when the window contains ... |
[
{
"content": "You are given a list of strings `words` and a string `target`. Your task is to find the minimum number of stickers that you need to spell out the `target` string. Each sticker is a string, and you may use each sticker unlimited times. If it is not possible to spell out `target` using the given sti... |
[
{
"content": "You are given a 2D grid of `n` x `n` binary values representing a map of an island. Each cell in the grid contains either a `0` (representing water) or a `1` (representing land). An island is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.