319 challenges in the catalogue. Browse freely; sign in to open the editor and submit.
CREATE TABLE Customers (
id INT PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE Orders (
id INT PRIMARY KEY,
customerId INT REFERENCES Customers(id)
);
Write a SQL query to find all customers who never order anything.
Return the result table with the column name Customers.
Input:
Customers table: | id | name | |----|-------| | 1 | Joe | | 2 | Henry | | 3 | Sam | | 4 | Max |
Orders table: | id | customerId | |----|------------| | 1 | 3 | | 2 | 1 |
Output:
| Customers | |-----------| | Henry | | Max |
Explanation: Henry (id=2) and Max (id=4) never placed any orders.
customerId in Orders is a foreign key referencing Customers.id.Cross-Site Request Forgery (CSRF) is an attack that forces an authenticated user to execute unwanted actions on a web application in which they're currently authenticated.
Your task is to implement an Express.js middleware function csrfProtection that validates a CSRF token for all state-changing HTTP requests.
POST, PUT, DELETE, and PATCH. Safe methods like GET, HEAD, and OPTIONS do not require a CSRF token.X-CSRF-TOKEN.req.session.csrfToken).next() to proceed.403 Forbidden response with the message: "Invalid or missing CSRF token".POST /update-profileX-CSRF-TOKEN: "xyz123"req.session.csrfToken: "xyz123"next().POST /delete-accountX-CSRF-TOKEN: "wrong"req.session.csrfToken: "xyz123"res.status(403).send("Invalid or missing CSRF token").You are an SRE tasked with setting up a comprehensive monitoring and alerting pipeline for a microservice using Prometheus, Grafana, and Alertmanager.
Given a service configuration with SLO targets, generate a complete monitoring stack configuration including:
rate() over 5m window)histogram_quantile()severity label and for durationalertname and serviceExample 1:
Input: {
serviceName: "api-gateway",
slo: { availability: 99.9, latencyP99Ms: 500 },
alertChannels: ["slack", "pagerduty"]
}
Output: {
prometheusRules: "groups:\n - name: api-gateway-sli\n rules: ...",
grafanaDashboard: "{ dashboard with 4 panels }",
alertmanagerConfig: "route:\n group_by: ['alertname', 'service']\n ..."
}
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.
Example 1:
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49. (Between index 1 and 8: Math.min(8, 7) * (8 - 1) = 49).
Example 2:
Input: height = [1,1]
Output: 1
n == height.length2 <= n <= 10^50 <= height[i] <= 10^4A message containing letters from A-Z can be encoded into numbers using the following mapping:
'A' -> "1"
'B' -> "2"
...
'Z' -> "26"
To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:
"AAJF" with the grouping (1 1 10 6)"KJF" with the grouping (11 10 6)Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".
Given a string s containing only digits, return the number of ways to decode it.
Example 1:
Input: s = "12"
Output: 2
Explanation: "12" could be decoded as "AB" (1 2) or "L" (12).
Example 2:
Input: s = "226"
Output: 3
Explanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
Example 3:
Input: s = "06"
Output: 0
Explanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
1 <= s.length <= 100s contains only digits and may contain leading zeros.You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.
Return the number of connected components in the graph.
Input: n = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2
Input: n = 5, edges = [[0,1],[1,2],[2,3],[3,4]]
Output: 1
1 <= n <= 20000 <= edges.length <= 5000edges[i].length == 20 <= ai <= bi < nai != biGiven a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.
Note that the same word in the dictionary may be reused multiple times in the segmentation.
Example 1:
Input: s = "leetcode", wordDict = ["leet","code"]
Output: true
Explanation: Return true because "leetcode" can be segmented as "leet code".
Example 2:
Input: s = "applepenapple", wordDict = ["apple","pen"]
Output: true
Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
Note that you are allowed to reuse a dictionary word.
Example 3:
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
Output: false
1 <= s.length <= 3001 <= wordDict.length <= 10001 <= wordDict[i].length <= 20s and wordDict[i] consist of only lowercase English letters.wordDict are unique.Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
Example 1:
Input: root = [1,2,3,null,5,null,4]
Output: [1,3,4]
Example 2:
Input: root = [1,null,3]
Output: [1,3]
Example 3:
Input: root = []
Output: []
[0, 100].-100 <= Node.val <= 100Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: s = "cbaebabacd", p = "abc"
Output: [0,6]
Explanation:
The substring with start index = 0 is "cba", which is an anagram of "abc".
The substring with start index = 6 is "bac", which is an anagram of "abc".
Example 2:
Input: s = "abab", p = "ab"
Output: [0,1,2]
Explanation:
The substring with start index = 0 is "ab", which is an anagram of "ab".
The substring with start index = 1 is "ba", which is an anagram of "ab".
The substring with start index = 2 is "ab", which is an anagram of "ab".
1 <= s.length, p.length <= 3 * 10^4s and p consist of lowercase English letters.You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the i-th person of height hi with exactly ki other people in front who have a height greater than or equal to hi.
Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array ans, where ans[j] = [hj, kj] is the attributes of the j-th person in the queue (ans[0] is the person at the front of the queue).
Input: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
Output: [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
Explanation:
Input: people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]
Output: [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]
1 <= people.length <= 20000 <= hi <= 10^60 <= ki < people.lengthGiven a string s, rearrange the characters of s so that any two adjacent characters are not the same.
Return any possible rearrangement of s or return "" if not possible.
Example 1:
Input: s = "aab"
Output: "aba"
Example 2:
Input: s = "aaab"
Output: ""
1 <= s.length <= 500s consists of lowercase English letters.Given an integer array nums that may contain duplicates, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
Example 1:
Input: nums = [1,2,2]
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
Example 2:
Input: nums = [0]
Output: [[],[0]]
1 <= nums.length <= 10-10 <= nums[i] <= 10level:metric:operationsfor duration to prevent flapping