Question: Have you already been a cut out of it? The cut piece can be of any size and orientation. You are only allowed to make one straight cut.
How Strong is an Egg?
You have two identical eggs. The number of floors has been reached. It is necessary to find out the solution?
Given 2 words, return true if it has a substring that is also an anagram of word 1.
LGE, GOOGLE => True
GEO, GOOGLE => False
A city bus station information, example, bus No. 1 stops at abcd station, bus no. 2 stops at cefg station. No. 1, thus return 1, ag is 2, because you need to transfer at station c,
Ask for a bus. You can design any data structures.
Sub-Array with the Largest Sum
You are given an array with integers (both positive and negative) in any random order. Find the sub-array with the largest sum
In the first task, we find the “center of mass” of the original cake at the intersection of two diagonals. Then we also find the "center of mass" of the cut piece. We make a cut along the line through these "centers of mass"
You can make it less than the previous increment. For example, let's first try at floor 14. If it breaks, then we need 13 more tries to find the solution. If it doesn't break, then we should try the floor 27 (14 + 13). If it breaks, we need 12 more to find the solution. So the initial 2 tries plus the additional 12 tries in the total. If it doesn't break, we can try 39 (27 + 12) and so on. Using 14 as the initial floor, we can reach up to floor 105 (14 + 13 + 12 + ... + 1) before we need more than 14 tries. Since we only need to cover the floors.
sliding window. O (n + m) Complexity O (n) Additional Memory
bool findSubstrAnagram(string s1, string s2){ if(s1.size() > s2.size()) return false; if(s1 == s2) return true; vector<char> mark_s1(256, 0); vector<char> mark_s2(256, 0); for(char c : s1){ mark_s1[c]++; } int count = 0; for(char c : s2){ if(mark_s2[c] < mark_s1[c]){ count++; mark_s2[c]++; } else{ count = 0; fill(mark_s2.begin(), mark_s2.end(), 0); } if(count == s1.size()) return true; } return false; }
Use BFS0-1 instead of the Ford-Bellman algorithm described in your solution. The vertices of the graph - routes, edges - the intersection of routes. Initially, we initialize 0 all routes, which include the initial stop. The answer is the minimum of the distances to all routes that include the terminus.
Kadane's algorithm runs in O (n) time. The calculator is not the one that keeps the bottom of the array. If you have an array of
function getMaxSubSum(arr) { var maxSum = arr[0], partialSum = 0; for (var i = 0; i < arr.length; i++) { partialSum += arr[i]; maxSum = Math.max(maxSum, partialSum); if (partialSum < 0) partialSum = 0; } return maxSum; }
Source: https://habr.com/ru/post/344788/
All Articles