319 challenges in the catalogue. Browse freely; sign in to open the editor and submit.
CREATE TABLE Logs (
id SERIAL PRIMARY KEY,
num VARCHAR(50)
);
id is the primary key and an auto-increment column.
Find all numbers that appear at least three times consecutively.
Return the result table with the column name ConsecutiveNums. Return the result in any order.
Input:
Logs table: | id | num | |----|-----| | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 1 | | 6 | 2 | | 7 | 2 |
Output:
| ConsecutiveNums | |-----------------| | 1 |
Explanation: 1 is the only number that appears consecutively for at least three times (rows 1, 2, 3).
Input:
Logs table: | id | num | |----|-----| | 1 | 1 | | 2 | 2 | | 3 | 1 | | 4 | 1 |
Output:
| ConsecutiveNums | |-----------------|
(Empty result - no number appears three times consecutively.)
id starts from 1 and auto-increments.Given the root of a binary tree, return the level order traversal of its nodes' values (i.e., from left to right, level by level).
Example 1:
Input: root = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]
Example 2:
Input: root = [1]
Output: [[1]]
Example 3:
Input: root = []
Output: []
[0, 2000].-1000 <= Node.val <= 1000Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)^2 + (y1 - y2)^2).
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).
Example 1:
Input: points = [[1,3],[-2,2]], k = 1
Output: [[-2,2]]
Explanation:
The distance between (1, 3) and the origin is sqrt(10).
The distance between (-2, 2) and the origin is sqrt(8).
Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].
Example 2:
Input: points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3],[-2,4]]
Explanation: The answer [[-2,4],[3,3]] would also be accepted.
1 <= k <= points.length <= 10^4-10^4 <= xi, yi <= 10^4Given two strings s and t of lengths m and n respectively, return the minimum window
substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
The testcases will be generated such that the answer is unique.
A substring is a contiguous sequence of characters within the string.
Example 1:
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
Example 2:
Input: s = "a", t = "a"
Output: "a"
Explanation: The entire string s is the minimum window.
Example 3:
Input: s = "a", t = "aa"
Output: ""
Explanation: Both 'a's from t must be included in the window.
Since the largest window of s only has one 'a', return empty string.
m == s.lengthn == t.length1 <= m, n <= 10^5s and t consist of uppercase and lowercase English letters.Could you find an algorithm that runs in O(m + n) time?
There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.
Arrows can be shot up vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.
Given the array points, return the minimum number of arrows that must be shot to burst all balloons.
Input: points = [[10,16],[2,8],[1,6],[7,12]]
Output: 2
Explanation: The balloons can be burst by 2 arrows:
Input: points = [[1,2],[3,4],[5,6],[7,8]]
Output: 4
Explanation: One arrow needs to be shot for each balloon for a total of 4 arrows.
Input: points = [[1,2],[2,3],[3,4],[4,5]]
Output: 2
Explanation: The balloons can be burst by 2 arrows:
1 <= points.length <= 10^5Implement a class FooBar with two methods foo and bar that are called from separate async contexts. They should alternate execution so that the output is "foobar" repeated n times.
foo() prints "foo" and bar() prints "bar". They run concurrently but must alternate: foo, bar, foo, bar, ...
class FooBar {
constructor(n: number);
foo(printFoo: () => void): Promise<void>;
bar(printBar: () => void): Promise<void>;
}
Input: n = 2
Output: "foobarfoobar"
Input: n = 1
Output: "foobar"
foo and bar are called concurrentlyAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.
Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.
Input: g = [1,2,3], s = [1,1]
Output: 1
Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3.
And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
You need to output 1.
Input: g = [1,2], s = [1,2,3]
Output: 2
Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2.
You have 3 cookies and their sizes are big enough to gratify all of the children,
You need to output 2.
1 <= g.length <= 3 * 10^40 <= s.length <= 3 * 10^41 <= g[i], s[j] <= 2^31 - 1Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Input: x = 123
Output: 321
Input: x = -123
Output: -321
Input: x = 120
Output: 21
-2^31 <= x <= 2^31 - 1Design a high-performance API Gateway that acts as a single entry point for a microservices architecture. The gateway should handle core cross-cutting concerns such as authentication, rate limiting, request routing, and protocol translation.
Example Scenario:
GET /orders/123 with Authorization: Bearer <token>order-service endpoint via Service Discovery.order-service:8080/orders/123.Write a SQL query to find all dates' Id with higher temperatures compared to its previous dates (yesterday).
Table: Weather
| Column Name | Type |
| :--- | :--- |
| id | int |
| recordDate | date |
| temperature | int |
id is the primary key for this table.
This table contains information about the temperature on a certain day.
Input:
Weather table:
| id | recordDate | temperature |
| :--- | :--- | :--- |
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
Output: | id | | :--- | | 2 | | 4 |
Explanation: In 2015-01-02, the temperature was higher than the previous day (10 -> 25). In 2015-01-04, the temperature was higher than the previous day (20 -> 30).
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".
Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".
Input: s = ""
Output: 0
0 <= s.length <= 3 * 10^4s[i] is '(', or ')'.Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
If target is not found in the array, return [-1, -1].
You must write an algorithm with O(log n) runtime complexity.
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1, -1]
Input: nums = [], target = 0
Output: [-1, -1]
0 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9nums is a non-decreasing array.-10^9 <= target <= 10^9points[i].length == 2-2^31 <= xstart < xend <= 2^31 - 1