id stringlengths 12 42 | benchmark stringclasses 5
values | prompt stringlengths 27 14k | reference dict | metadata dict |
|---|---|---|---|---|
apps-train-2361 | apps | You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th... | {
"input_output": "{\"inputs\": [\"6\\n1\\n2\\n3\\n4\\n5\\n6\\n\"], \"outputs\": [\"1 \\n1 2 \\n2 1 3 \\n3 1 2 4 \\n2 4 1 3 5 \\n3 4 1 5 2 6 \\n\"]}",
"starter_code": "",
"problem_id": 2361,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1353/D"
} |
apps-train-2362 | apps | $n$ robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous!
Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the loc... | {
"input_output": "{\n \"inputs\": [\n \"4\\n2\\n-1 -2 0 0 0 0\\n-1 -2 0 0 0 0\\n3\\n1 5 1 1 1 1\\n2 5 0 1 0 1\\n3 5 1 0 0 0\\n2\\n1337 1337 0 1 1 1\\n1336 1337 1 1 0 1\\n1\\n3 5 1 1 1 1\\n\"\n ],\n \"outputs\": [\n \"1 -1 -2\\n1 2 5\\n0\\n1 -100000 -100000\\n\"\n ]\n}",
"starter_code": "",
"problem_id"... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1196/C"
} |
apps-train-2363 | apps | There are $n$ athletes in front of you. Athletes are numbered from $1$ to $n$ from left to right. You know the strength of each athlete — the athlete number $i$ has the strength $s_i$.
You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.... | {
"input_output": "{\n \"inputs\": [\n \"5\\n5\\n3 1 2 6 4\\n6\\n2 1 3 2 4 3\\n4\\n7 9 3 1\\n2\\n1 1000\\n3\\n100 150 200\\n\"\n ],\n \"outputs\": [\n \"1\\n0\\n2\\n999\\n50\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2363,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1360/B"
} |
apps-train-2366 | apps | Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$.
Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For ... | {
"input_output": "{\n \"inputs\": [\n \"5\\n6\\n3 9 4 6 7 5\\n1\\n1000000\\n2\\n2 1\\n10\\n31 41 59 26 53 58 97 93 23 84\\n7\\n3 2 1 2 3 4 5\\n\"\n ],\n \"outputs\": [\n \"3\\n0\\n1\\n8\\n2\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2366,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1213/B"
} |
apps-train-2368 | apps | You have $n$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $i$-th gift consists of $a_i$ candies and $b_i$ oranges.
During one move, you can choose some gift $1 \le i \le n$ and do one of the following operations:
... | {
"input_output": "{\n \"inputs\": [\n \"5\\n3\\n3 5 6\\n3 2 3\\n5\\n1 2 3 4 5\\n5 4 3 2 1\\n3\\n1 1 1\\n2 2 2\\n6\\n1 1000000000 1000000000 1000000000 1000000000 1000000000\\n1 1 1 1 1 1\\n3\\n10 12 8\\n7 5 4\\n\"\n ],\n \"outputs\": [\n \"6\\n16\\n0\\n4999999995\\n7\\n\"\n ]\n}",
"starter_code": "",
"... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1399/B"
} |
apps-train-2369 | apps | This problem is a version of problem D from the same contest with some additional constraints and tasks.
There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$).
You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of ea... | {
"input_output": "{\n \"inputs\": [\n \"3\\n8\\n1 0\\n4 1\\n2 0\\n4 1\\n5 1\\n6 1\\n3 0\\n2 0\\n4\\n1 1\\n1 1\\n2 1\\n2 1\\n9\\n2 0\\n2 0\\n4 1\\n4 1\\n4 1\\n7 0\\n7 1\\n7 0\\n7 1\\n\"\n ],\n \"outputs\": [\n \"3 3\\n3 3\\n9 5\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2369,
"difficulty": "intro... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1183/G"
} |
apps-train-2371 | apps | You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ is a subarray consisting several first elements: the prefix of the array $a$... | {
"input_output": "{\n \"inputs\": [\n \"5\\n4\\n1 2 3 4\\n7\\n4 3 3 8 4 5 2\\n3\\n1 1 1\\n7\\n1 3 1 4 5 3 2\\n5\\n5 4 3 2 3\\n\"\n ],\n \"outputs\": [\n \"0\\n4\\n0\\n2\\n3\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2371,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1385/C"
} |
apps-train-2372 | apps | Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$).
In one move, you can do one of the following things:
Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increase $a_i$ by one); Append the copy of some (single) element of $a$ to the en... | {
"input_output": "{\n \"inputs\": [\n \"5\\n1\\n5\\n42\\n1337\\n1000000000\\n\"\n ],\n \"outputs\": [\n \"0\\n3\\n11\\n72\\n63244\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2372,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1426/C"
} |
apps-train-2375 | apps | The only difference between easy and hard versions is constraints.
You are given a sequence $a$ consisting of $n$ positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is as follows: $[\unde... | {
"input_output": "{\n \"inputs\": [\n \"6\\n8\\n1 1 2 2 3 2 1 1\\n3\\n1 3 3\\n4\\n1 10 10 1\\n1\\n26\\n2\\n2 1\\n3\\n1 1 1\\n\"\n ],\n \"outputs\": [\n \"7\\n2\\n4\\n1\\n1\\n3\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2375,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1335/E2"
} |
apps-train-2376 | apps | You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles.
In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove th... | {
"input_output": "{\n \"inputs\": [\n \"4\\n8 3\\n1 2\\n1 5\\n7 6\\n6 8\\n3 1\\n6 4\\n6 1\\n10 3\\n1 2\\n1 10\\n2 3\\n1 5\\n1 6\\n2 4\\n7 10\\n10 9\\n8 10\\n7 2\\n3 1\\n4 5\\n3 6\\n7 4\\n1 2\\n1 4\\n5 1\\n1 2\\n2 3\\n4 3\\n5 3\\n\"\n ],\n \"outputs\": [\n \"2\\n3\\n3\\n4\\n\"\n ]\n}",
"starter_code": "",... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1385/F"
} |
apps-train-2377 | apps | This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem.
You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele... | {
"input_output": "{\n \"inputs\": [\n \"4\\n5\\n4 7 2 3 9\\n5\\n3 5 8 1 7\\n5\\n1 4 5 7 12\\n4\\n0 2 1 3\\n\"\n ],\n \"outputs\": [\n \"2\\n2\\n0\\n2\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2377,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1367/F1"
} |
apps-train-2379 | apps | You are given a binary string $s$ consisting of $n$ zeros and ones.
Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like "010101 ..." or "101010 ..." (i.e. the subsequence shoul... | {
"input_output": "{\n \"inputs\": [\n \"4\\n4\\n0011\\n6\\n111111\\n5\\n10101\\n8\\n01010000\\n\"\n ],\n \"outputs\": [\n \"2\\n1 2 2 1 \\n6\\n1 2 3 4 5 6 \\n1\\n1 1 1 1 1 \\n4\\n1 1 1 1 1 2 3 4 \\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2379,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1399/D"
} |
apps-train-2380 | apps | You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | {
"input_output": "{\n \"inputs\": [\n \"6\\n9 2\\n010001010\\n9 3\\n111100000\\n7 4\\n1111111\\n10 3\\n1001110101\\n1 1\\n1\\n1 1\\n0\\n\"\n ],\n \"outputs\": [\n \"1\\n2\\n5\\n4\\n0\\n0\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2380,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1353/E"
} |
apps-train-2381 | apps | There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is staying at the $i$-th cell and the $i$-th character is 'L', the frog can jump o... | {
"input_output": "{\n \"inputs\": [\n \"6\\nLRLRRLL\\nL\\nLLR\\nRRRR\\nLLLLLL\\nR\\n\"\n ],\n \"outputs\": [\n \"3\\n2\\n3\\n1\\n7\\n1\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2381,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1324/C"
} |
apps-train-2383 | apps | Find the minimum area of a square land on which you can place two identical rectangular $a \times b$ houses. The sides of the houses should be parallel to the sides of the desired square land.
Formally, You are given two identical rectangles with side lengths $a$ and $b$ ($1 \le a, b \le 100$) — positive integers (y... | {
"input_output": "{\n \"inputs\": [\n \"8\\n3 2\\n4 2\\n1 1\\n3 1\\n4 7\\n1 3\\n7 4\\n100 100\\n\"\n ],\n \"outputs\": [\n \"16\\n16\\n4\\n9\\n64\\n9\\n64\\n40000\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2383,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1360/A"
} |
apps-train-2385 | apps | There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ which is one of the four characters 'U', 'R', 'D' and 'L'.
If $s_{i, j}$ ... | {
"input_output": "{\n \"inputs\": [\n \"3\\n1 2\\n01\\nRL\\n3 3\\n001\\n101\\n110\\nRLL\\nDLD\\nULL\\n3 3\\n000\\n000\\n000\\nRRD\\nRLD\\nULL\\n\"\n ],\n \"outputs\": [\n \"2 1\\n4 3\\n2 2\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2385,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1335/F"
} |
apps-train-2389 | apps | The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | {
"input_output": "{\n \"inputs\": [\n \"3\\n5 2\\nBGGGG\\n5 3\\nRBRGR\\n5 5\\nBBBRR\\n\"\n ],\n \"outputs\": [\n \"1\\n0\\n3\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2389,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1196/D2"
} |
apps-train-2391 | apps | You are given an array $a$ consisting of $n$ integers.
In one move, you can choose some index $i$ ($1 \le i \le n - 2$) and shift the segment $[a_i, a_{i + 1}, a_{i + 2}]$ cyclically to the right (i.e. replace the segment $[a_i, a_{i + 1}, a_{i + 2}]$ with $[a_{i + 2}, a_i, a_{i + 1}]$).
Your task is to sort the ini... | {
"input_output": "{\"inputs\": [\"5\\n5\\n1 2 3 4 5\\n5\\n5 4 3 2 1\\n8\\n8 4 5 2 3 6 7 3\\n7\\n5 2 1 6 4 7 3\\n6\\n1 2 3 3 6 4\\n\"], \"outputs\": [\"0\\n\\n6\\n3 1 3 2 2 3 \\n13\\n2 1 1 6 4 2 4 3 3 4 4 6 6 \\n-1\\n4\\n3 3 4 4 \\n\"]}",
"starter_code": "",
"problem_id": 2391,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1374/F"
} |
apps-train-2393 | apps | Polygon is not only the best platform for developing problems but also a square matrix with side $n$, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly... | {
"input_output": "{\n \"inputs\": [\n \"5\\n4\\n0010\\n0011\\n0000\\n0000\\n2\\n10\\n01\\n2\\n00\\n00\\n4\\n0101\\n1111\\n0101\\n0111\\n4\\n0100\\n1110\\n0101\\n0111\\n\"\n ],\n \"outputs\": [\n \"YES\\nNO\\nYES\\nYES\\nNO\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2393,
"difficulty": "introduct... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1360/E"
} |
apps-train-2395 | apps | A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$.
You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other digits of $x$ can be $0$, $1$ or $2$.
Let's define the ternary XOR ... | {
"input_output": "{\n \"inputs\": [\n \"4\\n5\\n22222\\n5\\n21211\\n1\\n2\\n9\\n220222021\\n\"\n ],\n \"outputs\": [\n \"11111\\n11111\\n11000\\n10211\\n1\\n1\\n110111011\\n110111010\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2395,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1328/C"
} |
apps-train-2396 | apps | You are given a string $s[1 \dots n]$ consisting of lowercase Latin letters. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$.
The string $s[1 \dots n]$ is called $c$-good if at least one of the following three conditions is satisfied: The length of $s$ is $1$, and it consists of the character $c$ (i.e. $s_... | {
"input_output": "{\n \"inputs\": [\n \"6\\n8\\nbbdcaaaa\\n8\\nasdfghjk\\n8\\nceaaaabb\\n8\\nbbaaddcc\\n1\\nz\\n2\\nac\\n\"\n ],\n \"outputs\": [\n \"0\\n7\\n4\\n5\\n1\\n1\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2396,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1385/D"
} |
apps-train-2397 | apps | Consider all binary strings of length $m$ ($1 \le m \le 60$). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly $2^m$ such strings in total.
The string $s$ is lexicographically smaller than the string $t$ (bot... | {
"input_output": "{\n \"inputs\": [\n \"5\\n3 3\\n010\\n001\\n111\\n4 3\\n000\\n111\\n100\\n011\\n1 1\\n1\\n1 1\\n0\\n3 2\\n00\\n01\\n10\\n\"\n ],\n \"outputs\": [\n \"100\\n010\\n0\\n1\\n11\\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2397,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1360/H"
} |
apps-train-2399 | apps | You are given a graph consisting of $n$ vertices and $m$ edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direction for all these edges.
You have to direct undirected edges in such... | {
"input_output": "{\n \"inputs\": [\n \"4\\n3 1\\n0 1 3\\n5 5\\n0 2 1\\n1 1 5\\n1 5 4\\n0 5 2\\n1 3 5\\n4 5\\n1 1 2\\n0 4 3\\n1 3 1\\n0 2 3\\n1 2 4\\n4 5\\n1 4 1\\n1 1 3\\n0 1 2\\n1 2 4\\n1 3 2\\n\"\n ],\n \"outputs\": [\n \"YES\\n3 1\\nYES\\n2 1\\n1 5\\n5 4\\n2 5\\n3 5\\nYES\\n1 2\\n3 4\\n3 1\\n3 2\\n2 4\\... | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1385/E"
} |
apps-train-2400 | apps | The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type... | {
"input_output": "{\n \"inputs\": [\n \"4\\n5\\n1 2 1 2 2\\n6\\n1 2 2 1 2 2\\n5\\n1 2 1 2 3\\n3\\n10 10 10\\n\"\n ],\n \"outputs\": [\n \"2\\n2 1 2 1 1 \\n2\\n1 2 1 2 1 2 \\n3\\n1 2 1 2 3\\n1\\n1 1 1 \\n\"\n ]\n}",
"starter_code": "",
"problem_id": 2400,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://codeforces.com/problemset/problem/1328/D"
} |
apps-train-2401 | apps | Given a pattern and a string str, find if str follows the same pattern.
Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
Example 1:
Input: pattern = "abba", str = "dog cat cat dog"
Output: true
Example 2:
Input:pattern = "abba", str = "dog ca... | {
"input_output": "{\"fn_name\": \"wordPattern\", \"inputs\": [[\"\\\"abba\\\"\", \"\\\"dog cat cat dog\\\"\"]], \"outputs\": [false]}",
"starter_code": "class Solution:\n def wordPattern(self, pattern: str, s: str) -> bool:",
"problem_id": 2401,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/word-pattern/"
} |
apps-train-2402 | apps | Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Note:
In the string, each word is separated by single space and there will not b... | {
"input_output": "{\"fn_name\": \"reverseWords\", \"inputs\": [[\"\\\"Let's take LeetCode contest\\\"\"]], \"outputs\": [\"s'teL\\\" ekat edoCteeL \\\"tsetnoc\"]}",
"starter_code": "class Solution:\n def reverseWords(self, s: str) -> str:",
"problem_id": 2402,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/reverse-words-in-a-string-iii/"
} |
apps-train-2403 | apps | We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.
Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not.
Example:
Input: 28
Output: True
Explanation: 28 = 1 + 2 + 4 + 7 + 14
Note:
The... | {
"input_output": "{\"fn_name\": \"checkPerfectNumber\", \"inputs\": [[28]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def checkPerfectNumber(self, num: int) -> bool:",
"problem_id": 2403,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/perfect-number/"
} |
apps-train-2404 | apps | Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.
Find the kth positive integer that is missing from this array.
Example 1:
Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive intege... | {
"input_output": "{\"fn_name\": \"findKthPositive\", \"inputs\": [[[2, 3, 4, 7, 11], 5]], \"outputs\": [9]}",
"starter_code": "class Solution:\n def findKthPositive(self, arr: List[int], k: int) -> int:",
"problem_id": 2404,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/kth-missing-positive-number/"
} |
apps-train-2405 | apps | A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:
-2: turn left 90 degrees
-1: turn right 90 degrees
1 <= x <= 9: move forward x units
Some of the grid squares are obstacles.
The i-th obstacle is at grid point (obstacles[i][0], obstacl... | {
"input_output": "{\"fn_name\": \"robotSim\", \"inputs\": [[[4, -1, 3], [[], []]]], \"outputs\": [25]}",
"starter_code": "class Solution:\n def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:",
"problem_id": 2405,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/walking-robot-simulation/"
} |
apps-train-2408 | apps | Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
Starter code:
```python
class Solution:
def firstUniqChar(self,... | {
"input_output": "{\"fn_name\": \"firstUniqChar\", \"inputs\": [[\"\\\"leetcode\\\"\"]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def firstUniqChar(self, s: str) -> int:",
"problem_id": 2408,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/first-unique-character-in-a-string/"
} |
apps-train-2410 | apps | Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) bei... | {
"input_output": "{\"fn_name\": \"isLongPressedName\", \"inputs\": [[\"\\\"alex\\\"\", \"\\\"aaleex\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isLongPressedName(self, name: str, typed: str) -> bool:",
"problem_id": 2410,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/long-pressed-name/"
} |
apps-train-2411 | apps | Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
Example 1:
Input: [3, 2, 1]
Output: 1
Explanation: The third maximum is 1.
Example 2:
Input: [1, 2]
Output: 2
Explanation: The third maximum... | {
"input_output": "{\"fn_name\": \"thirdMax\", \"inputs\": [[[3, 2, 1]]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def thirdMax(self, nums: List[int]) -> int:",
"problem_id": 2411,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/third-maximum-number/"
} |
apps-train-2412 | apps | Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.
We repeatedly make duplicate removals on S until we no longer can.
Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.
Exampl... | {
"input_output": "{\"fn_name\": \"removeDuplicates\", \"inputs\": [[\"\\\"abbaca\\\"\"]], \"outputs\": [\"\\\"ca\\\"\"]}",
"starter_code": "class Solution:\n def removeDuplicates(self, S: str) -> str:",
"problem_id": 2412,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/"
} |
apps-train-2413 | apps | Find the largest palindrome made from the product of two n-digit numbers.
Since the result could be very large, you should return the largest palindrome mod 1337.
Example:
Input: 2
Output: 987
Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
Note:
The range of n is [1,8].
Starter code:
```python
class Solution:
... | {
"input_output": "{\"fn_name\": \"largestPalindrome\", \"inputs\": [[1]], \"outputs\": [9]}",
"starter_code": "class Solution:\n def largestPalindrome(self, n: int) -> int:",
"problem_id": 2413,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/largest-palindrome-product/"
} |
apps-train-2415 | apps | Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Example 1:
Input: [1,3,5,6], 5
Output: 2
Example 2:
Input: [1,3,5,6], 2
Output: 1
Example 3:
Input: [1,3,5,6],... | {
"input_output": "{\"fn_name\": \"searchInsert\", \"inputs\": [[[1, 3, 5, 6], 5]], \"outputs\": [2]}",
"starter_code": "class Solution:\n def searchInsert(self, nums: List[int], target: int) -> int:",
"problem_id": 2415,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/search-insert-position/"
} |
apps-train-2416 | apps | Given a positive integer num, write a function which returns True if num is a perfect square else False.
Note: Do not use any built-in library function such as sqrt.
Example 1:
Input: 16
Returns: True
Example 2:
Input: 14
Returns: False
Credits:Special thanks to @elmirap for adding this problem and creating... | {
"input_output": "{\"fn_name\": \"isPerfectSquare\", \"inputs\": [[16]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isPerfectSquare(self, num: int) -> bool:",
"problem_id": 2416,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/valid-perfect-square/"
} |
apps-train-2417 | apps | Given an integer, return its base 7 string representation.
Example 1:
Input: 100
Output: "202"
Example 2:
Input: -7
Output: "-10"
Note:
The input will be in range of [-1e7, 1e7].
Starter code:
```python
class Solution:
def convertToBase7(self, num: int) -> str:
``` | {
"input_output": "{\"fn_name\": \"convertToBase7\", \"inputs\": [[100]], \"outputs\": [\"202\"]}",
"starter_code": "class Solution:\n def convertToBase7(self, num: int) -> str:",
"problem_id": 2417,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/base-7/"
} |
apps-train-2420 | apps | Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
Example 2:
Input: s = "rat", t = "car"
Output: false
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode c... | {
"input_output": "{\"fn_name\": \"isAnagram\", \"inputs\": [[\"\\\"anagram\\\"\", \"\\\"nagaram\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isAnagram(self, s: str, t: str) -> bool:",
"problem_id": 2420,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/valid-anagram/"
} |
apps-train-2421 | apps | Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.
Example 1:
Input: [3,2,3]
Output: 3
Example 2:
Input: [2,2,1,1,1,2,2]
Output: 2
Starter co... | {
"input_output": "{\"fn_name\": \"majorityElement\", \"inputs\": [[[3, 2, 3]]], \"outputs\": [3]}",
"starter_code": "class Solution:\n def majorityElement(self, nums: List[int]) -> int:",
"problem_id": 2421,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/majority-element/"
} |
apps-train-2422 | apps | Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).
Example 1:
Input: nums = [3,4,5,2]
Output: 12
Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(... | {
"input_output": "{\"fn_name\": \"maxProduct\", \"inputs\": [[[3, 4, 5, 2]]], \"outputs\": [12]}",
"starter_code": "class Solution:\n def maxProduct(self, nums: List[int]) -> int:",
"problem_id": 2422,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/"
} |
apps-train-2423 | apps | Given an array of integers nums, you start with an initial positive value startValue.
In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
Return the minimum positive value of startValue such that the step by step sum is never less than 1.
Example 1:
Input: n... | {
"input_output": "{\"fn_name\": \"minStartValue\", \"inputs\": [[[-3, 2, -3, 4, 2]]], \"outputs\": [5]}",
"starter_code": "class Solution:\n def minStartValue(self, nums: List[int]) -> int:",
"problem_id": 2423,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/"
} |
apps-train-2424 | apps | Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.
Note:
The length of both num1 and num2 is < 5100.
Both num1 and num2 contains only digits 0-9.
Both num1 and num2 does not contain any leading zero.
You must not use any built-in BigInteger library or convert the inp... | {
"input_output": "{\"fn_name\": \"addStrings\", \"inputs\": [[\"\\\"0\\\"\", \"\\\"0\\\"\"]], \"outputs\": [\"172\"]}",
"starter_code": "class Solution:\n def addStrings(self, num1: str, num2: str) -> str:",
"problem_id": 2424,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/add-strings/"
} |
apps-train-2426 | apps | Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i].
After this process, we have some array B.
Return the smallest possible difference between the maximum value of B and the minimum value of B.
Example 1:
Input: A = [1], K = 0
Output: 0
Explanation: B = [1]
... | {
"input_output": "{\"fn_name\": \"smallestRangeI\", \"inputs\": [[[1], 0]], \"outputs\": [0]}",
"starter_code": "class Solution:\n def smallestRangeI(self, A: List[int], K: int) -> int:",
"problem_id": 2426,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/smallest-range-i/"
} |
apps-train-2430 | apps | Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Example 1:
Input: 5
Output: True
Explanation:
The binary representation of 5 is: 101
Example 2:
Input: 7
Output: False
Explanation:
The binary representation of 7 is: 111.
Example 3:... | {
"input_output": "{\"fn_name\": \"hasAlternatingBits\", \"inputs\": [[5]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def hasAlternatingBits(self, n: int) -> bool:",
"problem_id": 2430,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/binary-number-with-alternating-bits/"
} |
apps-train-2431 | apps | Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k.
Example 1:
Input: [3, 1, 4, 1, 5], k = 2
Output: 2
Explanation: There... | {
"input_output": "{\"fn_name\": \"findPairs\", \"inputs\": [[[3, 1, 4, 1, 5], 2]], \"outputs\": [2]}",
"starter_code": "class Solution:\n def findPairs(self, nums: List[int], k: int) -> int:",
"problem_id": 2431,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/k-diff-pairs-in-an-array/"
} |
apps-train-2432 | apps | You're now a baseball game point recorder.
Given a list of strings, each string can be one of the 4 following types:
Integer (one round's score): Directly represents the number of points you get in this round.
"+" (one round's score): Represents that the points you get in this round are the sum of the last two vali... | {
"input_output": "{\"fn_name\": \"calPoints\", \"inputs\": [[[\"\\\"5\\\"\", \"\\\"2\\\"\", \"\\\"C\\\"\", \"\\\"D\\\"\", \"\\\"+\\\"\"]]], \"outputs\": [0]}",
"starter_code": "class Solution:\n def calPoints(self, ops: List[str]) -> int:",
"problem_id": 2432,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/baseball-game/"
} |
apps-train-2433 | apps | You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes.
Given a number K, we would want to reformat the strings such that each group contains exactly K characters, except for the first group which could be shorter... | {
"input_output": "{\"fn_name\": \"licenseKeyFormatting\", \"inputs\": [[\"\\\"5F3Z-2e-9-w\\\"\", 4]], \"outputs\": [\"\\\"5-F3Z2-E9W\\\"\"]}",
"starter_code": "class Solution:\n def licenseKeyFormatting(self, S: str, K: int) -> str:",
"problem_id": 2433,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/license-key-formatting/"
} |
apps-train-2434 | apps | We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).
Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
Exa... | {
"input_output": "{\"fn_name\": \"isOneBitCharacter\", \"inputs\": [[[1, 0, 0]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:",
"problem_id": 2434,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/1-bit-and-2-bit-characters/"
} |
apps-train-2436 | apps | Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example 1:
Input: "A man, a plan, a canal: Panama"
Output: true
Example 2:
Input: "race a car"
Output: false
Starter c... | {
"input_output": "{\"fn_name\": \"isPalindrome\", \"inputs\": [[\"\\\"A man, a plan, a canal: Panama\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isPalindrome(self, s: str) -> bool:",
"problem_id": 2436,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/valid-palindrome/"
} |
apps-train-2439 | apps | Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1:
Input: haystack = "hello", needle = "ll"
Output: 2
Example 2:
Input: haystack = "aaaaa", needle = "bba"
Output: -1
Clarification:
What should we return when needle is an emp... | {
"input_output": "{\"fn_name\": \"strStr\", \"inputs\": [[\"\\\"hello\\\"\", \"\\\"ll\\\"\"]], \"outputs\": [-1]}",
"starter_code": "class Solution:\n def strStr(self, haystack: str, needle: str) -> int:",
"problem_id": 2439,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/implement-strstr/"
} |
apps-train-2441 | apps | Given a string s of lower and upper case English letters.
A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:
0 <= i <= s.length - 2
s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
To make the string good, you can choose two adjace... | {
"input_output": "{\"fn_name\": \"makeGood\", \"inputs\": [[\"\\\"leEeetcode\\\"\"]], \"outputs\": [\"\\\"leetcode\\\"\"]}",
"starter_code": "class Solution:\n def makeGood(self, s: str) -> str:",
"problem_id": 2441,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/make-the-string-great/"
} |
apps-train-2442 | apps | Given a string s. You should re-order the string using the following algorithm:
Pick the smallest character from s and append it to the result.
Pick the smallest character from s which is greater than the last appended character to the result and append it.
Repeat step 2 until you cannot pick more characters.
Pick the... | {
"input_output": "{\"fn_name\": \"sortString\", \"inputs\": [[\"\\\"aaaabbbbcccc\\\"\"]], \"outputs\": [\"\\\"abccba\\\"abccba\"]}",
"starter_code": "class Solution:\n def sortString(self, s: str) -> str:",
"problem_id": 2442,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/increasing-decreasing-string/"
} |
apps-train-2443 | apps | Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
You can use each character in text at most once. Return the maximum number of instances that can be formed.
Example 1:
Input: text = "nlaebolko"
Output: 1
Example 2:
Input: text = "loonbalxballp... | {
"input_output": "{\"fn_name\": \"maxNumberOfBalloons\", \"inputs\": [[\"\\\"nlaebolko\\\"\"]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def maxNumberOfBalloons(self, text: str) -> int:",
"problem_id": 2443,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/maximum-number-of-balloons/"
} |
apps-train-2445 | apps | Given a word, you need to judge whether the usage of capitals in it is right or not.
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the first letter in th... | {
"input_output": "{\"fn_name\": \"detectCapitalUse\", \"inputs\": [[\"\\\"USA\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def detectCapitalUse(self, word: str) -> bool:",
"problem_id": 2445,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/detect-capital/"
} |
apps-train-2447 | apps | Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Note:
The vowels does not include the letter "y".
Starter code:
```python
class Solution:
def reverseVowels(self, s: str) ... | {
"input_output": "{\"fn_name\": \"reverseVowels\", \"inputs\": [[\"\\\"hello\\\"\"]], \"outputs\": [\"\\\"holle\\\"\"]}",
"starter_code": "class Solution:\n def reverseVowels(self, s: str) -> str:",
"problem_id": 2447,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/reverse-vowels-of-a-string/"
} |
apps-train-2448 | apps | Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
This is case sensitive, for example "Aa" is not considered a palindrome here.
Note:
Assume the length of given string will not exceed 1,010.
Example:
Input:
"abccccdd"
... | {
"input_output": "{\"fn_name\": \"longestPalindrome\", \"inputs\": [[\"\\\"abccccdd\\\"\"]], \"outputs\": [9]}",
"starter_code": "class Solution:\n def longestPalindrome(self, s: str) -> int:",
"problem_id": 2448,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/longest-palindrome/"
} |
apps-train-2449 | apps | Given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.
Return the minimum number of steps to make the given string empty.
A string is a subsequence of a given string, if it is generated by deleting some characters of a given string without changing i... | {
"input_output": "{\"fn_name\": \"removePalindromeSub\", \"inputs\": [[\"\\\"ababa\\\"\"]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def removePalindromeSub(self, s: str) -> int:",
"problem_id": 2449,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/remove-palindromic-subsequences/"
} |
apps-train-2451 | apps | Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom
note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Note:... | {
"input_output": "{\"fn_name\": \"canConstruct\", \"inputs\": [[\"\\\"a\\\"\", \"\\\"b\\\"\"]], \"outputs\": [false]}",
"starter_code": "class Solution:\n def canConstruct(self, ransomNote: str, magazine: str) -> bool:",
"problem_id": 2451,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/ransom-note/"
} |
apps-train-2452 | apps | We have a collection of stones, each stone has a positive integer weight.
Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:
If x == y, both stones are totally destroyed;
If x != y, the stone of weight x is totally d... | {
"input_output": "{\"fn_name\": \"lastStoneWeight\", \"inputs\": [[[2,7,4,1,8,1]]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:",
"problem_id": 2452,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/last-stone-weight/"
} |
apps-train-2453 | apps | Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle wh... | {
"input_output": "{\"fn_name\": \"isHappy\", \"inputs\": [[19]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isHappy(self, n: int) -> bool:",
"problem_id": 2453,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/happy-number/"
} |
apps-train-2454 | apps | Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...
Example 1:
Input: 1
Output: "A"
Example 2:
Input: 28
Output: "AB"
Example 3:
Input: 701
Output: "ZY"
Starter c... | {
"input_output": "{\"fn_name\": \"convertToTitle\", \"inputs\": [[1]], \"outputs\": [\"A\"]}",
"starter_code": "class Solution:\n def convertToTitle(self, n: int) -> str:",
"problem_id": 2454,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/excel-sheet-column-title/"
} |
apps-train-2456 | apps | Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
Note that after backspacing an empty text, the text will continue empty.
Example 1:
Input: S = "ab#c", T = "ad#c"
Output: true
Explanation: Both S and T become "ac".
Example 2:
Input: S = "... | {
"input_output": "{\"fn_name\": \"backspaceCompare\", \"inputs\": [[\"\\\"ab#c\\\"\", \"\\\"ad#c\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def backspaceCompare(self, S: str, T: str) -> bool:",
"problem_id": 2456,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/backspace-string-compare/"
} |
apps-train-2457 | apps | Given an array of integers nums, write a method that returns the "pivot" index of this array.
We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.
If no such index exists, we should return -1. If there are multiple p... | {
"input_output": "{\"fn_name\": \"pivotIndex\", \"inputs\": [[[1, 7, 3, 6, 5, 6]]], \"outputs\": [3]}",
"starter_code": "class Solution:\n def pivotIndex(self, nums: List[int]) -> int:",
"problem_id": 2457,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/find-pivot-index/"
} |
apps-train-2458 | apps | Balanced strings are those who have equal quantity of 'L' and 'R' characters.
Given a balanced string s split it in the maximum amount of balanced strings.
Return the maximum amount of splitted balanced strings.
Example 1:
Input: s = "RLRRLLRLRL"
Output: 4
Explanation: s can be split into "RL", "RRLL", "RL", "RL", ea... | {
"input_output": "{\"fn_name\": \"balancedStringSplit\", \"inputs\": [[\"\\\"RLRRLLRLRL\\\"\"]], \"outputs\": [5]}",
"starter_code": "class Solution:\n def balancedStringSplit(self, s: str) -> int:",
"problem_id": 2458,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/split-a-string-in-balanced-strings/"
} |
apps-train-2459 | apps | Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.
Note:
All letters in hexadecimal (a-f) must be in lowercase.
The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character '0'; oth... | {
"input_output": "{\"fn_name\": \"toHex\", \"inputs\": [[26]], \"outputs\": [\"1a\"]}",
"starter_code": "class Solution:\n def toHex(self, num: int) -> str:",
"problem_id": 2459,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/convert-a-number-to-hexadecimal/"
} |
apps-train-2460 | apps | Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Example:
Input: [-2,1,-3,4,-1,2,1,-5,4],
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Follow up:
If you have figured out the O(n) solution, try coding another solu... | {
"input_output": "{\"fn_name\": \"maxSubArray\", \"inputs\": [[[-2, 1, -3, 4, -1, 2, 1, -5, 4]]], \"outputs\": [6]}",
"starter_code": "class Solution:\n def maxSubArray(self, nums: List[int]) -> int:",
"problem_id": 2460,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/maximum-subarray/"
} |
apps-train-2462 | apps | Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
Example 1:
Input: "A"
Output: 1
Example 2:
Input: "AB"
Output: 28
Example 3:
Input: "ZY"
Output: 701
Starter code... | {
"input_output": "{\"fn_name\": \"titleToNumber\", \"inputs\": [[\"\\\"A\\\"\"]], \"outputs\": [-20284]}",
"starter_code": "class Solution:\n def titleToNumber(self, s: str) -> int:",
"problem_id": 2462,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/excel-sheet-column-number/"
} |
apps-train-2463 | apps | Given an array A of integers, return true if and only if it is a valid mountain array.
Recall that A is a mountain array if and only if:
A.length >= 3
There exists some i with 0 < i < A.length - 1 such that:
A[0] < A[1] < ... A[i-1] < A[i]
A[i] > A[i+1] > ... > A[A.length - 1]
Example 1:
Input: [2,1]
... | {
"input_output": "{\"fn_name\": \"validMountainArray\", \"inputs\": [[[2, 1]]], \"outputs\": [false]}",
"starter_code": "class Solution:\n def validMountainArray(self, A: List[int]) -> bool:",
"problem_id": 2463,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/valid-mountain-array/"
} |
apps-train-2465 | apps | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number N on the chalkboard. On each player's turn, that player makes a move consisting of:
Choosing any x with 0 < x < N and N % x == 0.
Replacing the number N on the chalkboard with N - x.
Also, if a player cannot make a move,... | {
"input_output": "{\"fn_name\": \"divisorGame\", \"inputs\": [[2]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def divisorGame(self, N: int) -> bool:",
"problem_id": 2465,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/divisor-game/"
} |
apps-train-2466 | apps | Given a square matrix mat, return the sum of the matrix diagonals.
Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.
Example 1:
Input: mat = [[1,2,3],
[4,5,6],
[7,8,9]]
Output: 25
Expl... | {
"input_output": "{\"fn_name\": \"diagonalSum\", \"inputs\": [[[[1, 2, 3], [4, 5, 6], [7, 8, 9], [], []]]], \"outputs\": [25]}",
"starter_code": "class Solution:\n def diagonalSum(self, mat: List[List[int]]) -> int:",
"problem_id": 2466,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/matrix-diagonal-sum/"
} |
apps-train-2469 | apps | Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).
More formally check if there exists two indices i and j such that :
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
Example 1:
Input: arr = [10,2,5,3]
Output: true
Explanation: N = 10 is t... | {
"input_output": "{\"fn_name\": \"checkIfExist\", \"inputs\": [[[10, 2, 5, 3]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def checkIfExist(self, arr: List[int]) -> bool:",
"problem_id": 2469,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/check-if-n-and-its-double-exist/"
} |
apps-train-2471 | apps | You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on... | {
"input_output": "{\"fn_name\": \"rob\", \"inputs\": [[[1, 2, 3, 1]]], \"outputs\": [4]}",
"starter_code": "class Solution:\n def rob(self, nums: List[int]) -> int:",
"problem_id": 2471,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/house-robber/"
} |
apps-train-2472 | apps | You are given a string representing an attendance record for a student. The record only contains the following three characters:
'A' : Absent.
'L' : Late.
'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
... | {
"input_output": "{\"fn_name\": \"checkRecord\", \"inputs\": [[\"\\\"PPALLP\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def checkRecord(self, s: str) -> bool:",
"problem_id": 2472,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/student-attendance-record-i/"
} |
apps-train-2474 | apps | Implement int sqrt(int x).
Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
Example 1:
Input: 4
Output: 2
Example 2:
Input: 8
Output: 2
Explanat... | {
"input_output": "{\"fn_name\": \"mySqrt\", \"inputs\": [[4]], \"outputs\": [2]}",
"starter_code": "class Solution:\n def mySqrt(self, x: int) -> int:",
"problem_id": 2474,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/sqrtx/"
} |
apps-train-2478 | apps | Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
Starter cod... | {
"input_output": "{\"fn_name\": \"findTheDifference\", \"inputs\": [[\"\\\"abcd\\\"\", \"\\\"abcde\\\"\"]], \"outputs\": [\"e\"]}",
"starter_code": "class Solution:\n def findTheDifference(self, s: str, t: str) -> str:",
"problem_id": 2478,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/find-the-difference/"
} |
apps-train-2480 | apps | We have n chips, where the position of the ith chip is position[i].
We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:
position[i] + 2 or position[i] - 2 with cost = 0.
position[i] + 1 or position[i] - 1 with cost = 1.
Return the minimum co... | {
"input_output": "{\"fn_name\": \"minCostToMoveChips\", \"inputs\": [[[1, 2, 3]]], \"outputs\": [1]}",
"starter_code": "class Solution:\n def minCostToMoveChips(self, position: List[int]) -> int:",
"problem_id": 2480,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/"
} |
apps-train-2483 | apps | Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.
Example 1:
Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
Examp... | {
"input_output": "{\"fn_name\": \"uniqueOccurrences\", \"inputs\": [[[1, 2, 2, 1, 1, 3]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def uniqueOccurrences(self, arr: List[int]) -> bool:",
"problem_id": 2483,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/unique-number-of-occurrences/"
} |
apps-train-2484 | apps | For two strings s and t, we say "t divides s" if and only if s = t + ... + t (t concatenated with itself 1 or more times)
Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.
Example 1:
Input: str1 = "ABCABC", str2 = "ABC"
Output: "ABC"
Example 2:
Input: str1 = "ABABAB... | {
"input_output": "{\"fn_name\": \"gcdOfStrings\", \"inputs\": [[\"\\\"ABCABC\\\"\", \"\\\"ABC\\\"\"]], \"outputs\": [\"\"]}",
"starter_code": "class Solution:\n def gcdOfStrings(self, str1: str, str2: str) -> str:",
"problem_id": 2484,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/greatest-common-divisor-of-strings/"
} |
apps-train-2487 | apps | Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Example 1:
Input: "abab"
Output: True
Explanation: It's the... | {
"input_output": "{\"fn_name\": \"repeatedSubstringPattern\", \"inputs\": [[\"\\\"abab\\\"\"]], \"outputs\": [false]}",
"starter_code": "class Solution:\n def repeatedSubstringPattern(self, s: str) -> bool:",
"problem_id": 2487,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/repeated-substring-pattern/"
} |
apps-train-2489 | apps | Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
Example 1:
In... | {
"input_output": "{\"fn_name\": \"maxProfit\", \"inputs\": [[[7, 1, 5, 3, 6, 4]]], \"outputs\": [5]}",
"starter_code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:",
"problem_id": 2489,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock/"
} |
apps-train-2491 | apps | Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false.
Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2... | {
"input_output": "{\"fn_name\": \"buddyStrings\", \"inputs\": [[\"\\\"ab\\\"\", \"\\\"ba\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def buddyStrings(self, A: str, B: str) -> bool:",
"problem_id": 2491,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/buddy-strings/"
} |
apps-train-2492 | apps | The Leetcode file system keeps a log each time some user performs a change folder operation.
The operations are described below:
"../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
"./" : Remain in the same folder.
"x/" : Move to the child folder... | {
"input_output": "{\"fn_name\": \"minOperations\", \"inputs\": [[[\"\\\"d1/\\\"\", \"\\\"d2/\\\"\", \"\\\"../\\\"\", \"\\\"d21/\\\"\", \"\\\"./\\\"\"]]], \"outputs\": [5]}",
"starter_code": "class Solution:\n def minOperations(self, logs: List[str]) -> int:",
"problem_id": 2492,
"difficulty": "introductory"... | {
"split": "train",
"url": "https://leetcode.com/problems/crawler-log-folder/"
} |
apps-train-2494 | apps | Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
Example 1:
Input: address = "1.1.1.1"
Output: "1[.]1[.]1[.]1"
Example 2:
Input: address = "255.100.50.0"
Output: "255[.]100[.]50[.]0"
Constraints:
The given address is a valid... | {
"input_output": "{\"fn_name\": \"defangIPaddr\", \"inputs\": [[\"\\\"1.1.1.1\\\"\"]], \"outputs\": [\"\\\"1[.]1[.]1[.]1\\\"\"]}",
"starter_code": "class Solution:\n def defangIPaddr(self, address: str) -> str:",
"problem_id": 2494,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/defanging-an-ip-address/"
} |
apps-train-2495 | apps | Given two integer arrays of equal length target and arr.
In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps.
Return True if you can make arr equal to target, or False otherwise.
Example 1:
Input: target = [1,2,3,4], arr = [2,4,1,3]
Output: true
Expla... | {
"input_output": "{\"fn_name\": \"canBeEqual\", \"inputs\": [[[1, 2, 3, 4], [2, 4, 1, 3]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def canBeEqual(self, target: List[int], arr: List[int]) -> bool:",
"problem_id": 2495,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays/"
} |
apps-train-2496 | apps | Given a date, return the corresponding day of the week for that date.
The input is given as three integers representing the day, month and year respectively.
Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
Example 1:
Input: day = 31, mon... | {
"input_output": "{\"fn_name\": \"dayOfTheWeek\", \"inputs\": [[31, 8, 2019]], \"outputs\": [\"Saturday\"]}",
"starter_code": "class Solution:\n def dayOfTheWeek(self, day: int, month: int, year: int) -> str:",
"problem_id": 2496,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/day-of-the-week/"
} |
apps-train-2497 | apps | Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.
Example 1:
Input: arr = [2,6,4,1]
Output: false
Explanation: There are no three consecutive odds.
Example 2:
Input: arr = [1,2,34,3,4,5,7,23,12]
Output: true
Explanation: [5,7,23] are three conse... | {
"input_output": "{\"fn_name\": \"threeConsecutiveOdds\", \"inputs\": [[[2, 6, 4, 1]]], \"outputs\": [false]}",
"starter_code": "class Solution:\n def threeConsecutiveOdds(self, arr: List[int]) -> bool:",
"problem_id": 2497,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/three-consecutive-odds/"
} |
apps-train-2498 | apps | In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.
Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted... | {
"input_output": "{\"fn_name\": \"isAlienSorted\", \"inputs\": [[[\"\\\"hello\\\"\", \"\\\"leetcode\\\"\"], \"\\\"hlabcdefgijkmnopqrstuvwxyz\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isAlienSorted(self, words: List[str], order: str) -> bool:",
"problem_id": 2498,
"difficulty": "... | {
"split": "train",
"url": "https://leetcode.com/problems/verifying-an-alien-dictionary/"
} |
apps-train-2499 | apps | In a deck of cards, each card has an integer written on it.
Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:
Each group has exactly X cards.
All the cards in each group have the same integer.
Example 1:
Input: deck = [1,2,3,4,4... | {
"input_output": "{\"fn_name\": \"hasGroupsSizeX\", \"inputs\": [[[1, 2, 3, 4, 4, 3, 2, 1]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def hasGroupsSizeX(self, deck: List[int]) -> bool:",
"problem_id": 2499,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/"
} |
apps-train-2500 | apps | Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.
Return the power of the string.
Example 1:
Input: s = "leetcode"
Output: 2
Explanation: The substring "ee" is of length 2 with the character 'e' only.
Example 2:
Input: s = "abbcccddddeee... | {
"input_output": "{\"fn_name\": \"maxPower\", \"inputs\": [[\"\\\"leetcode\\\"\"]], \"outputs\": [2]}",
"starter_code": "class Solution:\n def maxPower(self, s: str) -> int:",
"problem_id": 2500,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/consecutive-characters/"
} |
apps-train-2501 | apps | Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the ... | {
"input_output": "{\"fn_name\": \"reverseStr\", \"inputs\": [[\"\\\"abcdefg\\\"\", 2]], \"outputs\": [\"a\\\"bcedfg\\\"\"]}",
"starter_code": "class Solution:\n def reverseStr(self, s: str, k: int) -> str:",
"problem_id": 2501,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/reverse-string-ii/"
} |
apps-train-2504 | apps | Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays.
A subarray is a contiguous subsequence of the array.
Return the sum of all odd-length subarrays of arr.
Example 1:
Input: arr = [1,4,2,5,3]
Output: 58
Explanation: The odd-length subarrays of arr and their sums are:
[1] =... | {
"input_output": "{\"fn_name\": \"sumOddLengthSubarrays\", \"inputs\": [[[1, 4, 2, 5, 3]]], \"outputs\": [58]}",
"starter_code": "class Solution:\n def sumOddLengthSubarrays(self, arr: List[int]) -> int:",
"problem_id": 2504,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/sum-of-all-odd-length-subarrays/"
} |
apps-train-2505 | apps | An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.
Two rectangles overlap if... | {
"input_output": "{\"fn_name\": \"isRectangleOverlap\", \"inputs\": [[[0, 0, 2, 2], [1, 1, 3, 3]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:",
"problem_id": 2505,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/rectangle-overlap/"
} |
apps-train-2506 | apps | Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may ... | {
"input_output": "{\"fn_name\": \"isIsomorphic\", \"inputs\": [[\"\\\"egg\\\"\", \"\\\"add\\\"\"]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:",
"problem_id": 2506,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/isomorphic-strings/"
} |
apps-train-2507 | apps | You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once).
Return the sum of lengths of all good strings in words.
Example 1:
Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output: 6
Explanation:
The str... | {
"input_output": "{\"fn_name\": \"countCharacters\", \"inputs\": [[[\"\\\"cat\\\"\", \"\\\"bt\\\"\", \"\\\"hat\\\"\", \"\\\"tree\\\"\"], \"\\\"atach\\\"\"]], \"outputs\": [10]}",
"starter_code": "class Solution:\n def countCharacters(self, words: List[str], chars: str) -> int:",
"problem_id": 2507,
"difficu... | {
"split": "train",
"url": "https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/"
} |
apps-train-2508 | apps | Students are asked to stand in non-decreasing order of heights for an annual photo.
Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height.
Notice that when a group of students is selected they can reorder in any possible way between themselves an... | {
"input_output": "{\"fn_name\": \"heightChecker\", \"inputs\": [[[1, 1, 4, 2, 1, 3]]], \"outputs\": [3]}",
"starter_code": "class Solution:\n def heightChecker(self, heights: List[int]) -> int:",
"problem_id": 2508,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/height-checker/"
} |
apps-train-2511 | apps | In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times.
Return the element repeated N times.
Example 1:
Input: [1,2,3,3]
Output: 3
Example 2:
Input: [2,1,2,5,3,2]
Output: 2
Example 3:
Input: [5,1,5,2,5,3,5,4]
Output: 5
Note:
4 <= A.length <= 10000
0 <=... | {
"input_output": "{\"fn_name\": \"repeatedNTimes\", \"inputs\": [[[1, 2, 3, 3]]], \"outputs\": [3]}",
"starter_code": "class Solution:\n def repeatedNTimes(self, A: List[int]) -> int:",
"problem_id": 2511,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/n-repeated-element-in-size-2n-array/"
} |
apps-train-2516 | apps | Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
Example 1:
Input: nums = [1,2,3,1], k = 3
Output: true
Example 2:
Input: nums = [1,0,1,1], k = 1
Output: true
... | {
"input_output": "{\"fn_name\": \"containsNearbyDuplicate\", \"inputs\": [[[1, 2, 3, 1], 3]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:",
"problem_id": 2516,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/contains-duplicate-ii/"
} |
apps-train-2518 | apps | Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.
We define an array is non-decreasing if array[i] holds for every i (1
Example 1:
Input: [4,2,3]
Output: True
Explanation: You could modify the first 4 to 1 to get a non-decreasing array.
Exa... | {
"input_output": "{\"fn_name\": \"checkPossibility\", \"inputs\": [[[4, 2, 3]]], \"outputs\": [true]}",
"starter_code": "class Solution:\n def checkPossibility(self, nums: List[int]) -> bool:",
"problem_id": 2518,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/non-decreasing-array/"
} |
apps-train-2522 | apps | The count-and-say sequence is the sequence of integers with the first five terms as following:
1. 1
2. 11
3. 21
4. 1211
5. 111221
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
Given an integer n, generate the nth term of the c... | {
"input_output": "{\"fn_name\": \"countAndSay\", \"inputs\": [[1]], \"outputs\": [\"1\"]}",
"starter_code": "class Solution:\n def countAndSay(self, n: int) -> str:",
"problem_id": 2522,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/count-and-say/"
} |
apps-train-2523 | apps | Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.
Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.
Example 1:
Input: [1, 2, 2, 3, 1]
Output: 2
Explanatio... | {
"input_output": "{\"fn_name\": \"findShortestSubArray\", \"inputs\": [[[1, 2, 2, 3, 1]]], \"outputs\": [2]}",
"starter_code": "class Solution:\n def findShortestSubArray(self, nums: List[int]) -> int:",
"problem_id": 2523,
"difficulty": "introductory"
} | {
"split": "train",
"url": "https://leetcode.com/problems/degree-of-an-array/"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.