A wonderful string is a string where at most one letter appears an odd number of times.
"abab"are wonderful, but
Given a string
word that consists of the first ten lowercase English letters (
'j'), return the number of wonderful non-empty substrings in
word. If the same substring appears multiple times in
word, then count each occurrence separately.
A substring is a contiguous sequence of characters in a string.
Input: word = "aba"
Explanation: The four wonderful substrings are underlined below:
- "aba" -> "a"
- "aba" -> "b"
- "aba" ->…
Stop the grind. Study with plan! Here’s the patterns that covers 95% of the questions you’ll see on LeetCode.
Implicitly Sorted Array
DFS on Tree
The first step to getting a job at Google is to pass the online assessment, commonly referred as “OA”. The OA is given to candidates immediately after your application is approved by the initial screening. If you pass the online assessment, you will move on to the next round which is commonly phone interview screening. Although a recruiter may skip online assessment based on role/position and years of experience. In 2021, certain Google offices are skipping online assessment together.
The most common format of an OA is two coding questions to complete them within one hours to 90 minutes. The…
The first step to getting a job at Twitter is to pass the online assessment, commonly referred as “OA”. The most common format is a test with two to three questions to complete them within 1–1.5 hours. The assessment result will be used to decide if the candidate can move on to the on-site interviews.
The first step to getting a job at Amazon is to pass the online assessment, commonly referred as “OA”. Candidates are sent a test with 1–2 questions to complete them within 1.5 hours. The assessment result will be used to decide if the candidate can move on to the on-site interviews.
Here we have compiled a list of all online assessment questions for you:
In a string composed of
'X' characters, like
"RXXLRXRXL", a move consists of either replacing one occurrence of
"LX", or replacing one occurrence of
"XR". Given the starting string
start and the ending string
True if and only if there exists a sequence of moves to transform one string to the other.
Input: start = "RXXLRXRXL", end = "XRLXXRRLX"
We can transform start to end following these steps:
Input: start = "LLR", end = "RRL"
Given a complete binary tree, count the number of nodes.
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
/ \ /
4 5 6Output: 6
Asked recently by Google, Amazon and Microsoft.
The trivial solution is to traverse the tree and count the number of nodes and that would cost…
n nodes labeled from
n-1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.
Input: n = 5, and edges = [[0,1], [0,2], [0,3], [1,4]]
Input: n = 5, and edges = [[0,1], [1,2], [2,3], [1,3], [1,4]]
Before solving the problem, we have to know the definitions.
A tree is a special undirected graph. It satisfy two properties
Being connected means you can start from…
“Dynamic programming”, an awfully scary name. What does it even mean?? What’s so “dynamic” about programming?
The name was invented by Richard Bellman in the 1950s when computers are still decades away. So by “programming” he really did NOT mean programming as in coding at a computer. Bellman was a mathematician, and what he really meant by programming was “planning” and “decision making”.
Trivia time: according to Wikipedia, Bellman was working at RAND corporation, and it was hard to get mathematical research funding at the time. To disguise the fact that he was conducting mathematical research, he phrased his research…
Dynamic programming is probably the trickiest and most-feared interview question type. The hardest parts are 1) to know it’s a dynamic programming question to begin with 2) to find the subproblem.
We looked at a ton of dynamic programming questions and summarized common patterns and subproblems.
We also highlighted the keywords that indicate it’s likely a dynamic programming problem.
This is the most common type of DP problem and a good place to get a feel of dynamic programming. In the recurrence relation,
dp[i] normally means max/min/best value for the sequence ending at index i.