kandi X-RAY | interview Summary
kandi X-RAY | interview Summary
extern "C" 的作用是让 C++ 编译器将 extern "C" 声明的代码当作 C 语言代码处理，可以避免 C++ 因符号修饰导致代码不能和C语言库中的符号进行链接的问题。.
Top functions reviewed by kandi - BETA
interview Key Features
interview Examples and Code Snippets
def set(self, results, query): """Set the result for the given query key in the cache. When updating an entry, updates its position to the front of the LRU list. If the entry is new and the cache is at capacity, removes the o
def within_past_week(self, timestamp): """Return True if timestamp is within past week, False otherwise.""" ...
def extract_max_priority_page(self): """Return the highest priority link in `links_to_crawl`.""" pass
Trending Discussions on interview
Recently in a job interview, they ask me "how to solve Parallel Inheritance Hierarchies when we try to reuse code through inheritance". I thought on Aggregation or Composition, but i was a little confused on making an example based on that.
So I decided to leave it pending to deepen concepts later, but after investigating it did not end up forming a precise answer to that question, could someone explain me a solution or an example to this?...
ANSWERAnswered 2022-Feb-27 at 14:51
Parallel Inheritance Hierarchies makes many unnecessary classes and makes code very fragile and tightly coupled.
For example, we have class
Sportsman and its
So I'm preparing for a technical interview, and one of my practice questions is the Kth smallest number. I know that I can do a sort for O(n * log(n)) time and use a heap for O(n * log(k)). However I also know I can partition it (similar to quicksort) for an average case of O(n).
The actual calculated average time complexity should be:
I've double checked this math using WolframAlpha, and it agrees.
So I've coded my solution, and then I calculated the actual average time complexity on random data sets. For small values of n, it's pretty close. For example n=5 might give me an actual of around 6.2 when I expect around 5.7. This slightly more error is consistent.
This only gets worse as I increase the value of n. For example, for n=5000, I get around 15,000 for my actual average time complexity, when it should be slightly less than 10,000.
So basically, my question is where are these extra iterations coming from? Is my code wrong, or is it my math? My code is below:...
ANSWERAnswered 2022-Feb-27 at 08:40
As you and others have pointed out in the comments, your calculation assumed that the array was split in half on each iteration by the random pivot, which is incorrect. This uneven splitting has a significant impact: when the element you're trying to select is the actual median, for instance, the expected size of the array after one random pivot choice is 75% of the original, since you'll always choose the larger of the two arrays.
For an accurate estimate of the expected comparisons for each value of
k, David Eppstein published an accessible analysis here and derives this formula:
This is a very close estimate for your values, even though this assumes no duplicates in the array.
Calculating the expected number of comparisons for k from
n-1, as you do, gives
~7.499 * 10^7 total comparisons when
n=5000, or almost exactly
15,000 comparisons per call of Quickselect as you observed.
I was introduced to an example interview question, where given a 2D array of characters and a word, find the word in the array, where the next character of the word is either to the right or below the previous character, and return a list of the co-ordinates of each character found.
I wrote the following code to solve this:...
ANSWERAnswered 2022-Feb-03 at 00:43
I disagree with your search depth being O(Wlog(W)). In the worst case, where every intermediate letter (except the last) matches the word, your recursion will have a branching factor of 2, and will explore
2^W paths. Take, as an example, an extremely large grid, filled entirely with
As, and a sole
B in the lower right corner, and a search word
AAA...AB. You can see how that would explode exponentially (with respect to W).
You are correct too, in that you'd ignore the smaller term, so overall I think the time complexity should be O(RC*2^W).
I'm currently studying for a technical interview and I'm just going through the leetcode grind. I came across a question that is apparently asked pretty frequently by the company I'm about to interview at so I attempted it. I couldn't quite get it so I looked to the solution and came across this solution....
ANSWERAnswered 2021-Dec-19 at 00:30
This happens because
prev's reference is being pointed by
res when you do
res=[prev], basically the address where the actual
prev array is stored is pointed, as the prev updates, it also show changes in res.
I had an interview recently and was asked to solve the following problem using Python:
Write a function:...
ANSWERAnswered 2021-Sep-16 at 02:01
Not the most elegant. This assumes that e.g. -3 is single digit.
This algorithm will play by the rules set. Considering the constraints:
- The number is -10,000 to 10,000
- There is at least one element which satisfies the condition
Then we can just guard all numbers beyond 9 to be the lowest -10,001 so that they are not considered to be max. We don't need to care for numbers lower than -9 as we are sure there is at least 1 element (that is a single digit whether positive or negative, either way greater than those numbers lower than -9) that will satisfy the condition.
During the job interview, I was asked how to optimize a component in React.
So I answered with an example of using useCallback and useMemo hooks.
Because whenever a components re-renders, functions and variables declared inside of the component are newly created which results in those newly created values occupying memory space.
However, with a help of those two hooks, it is possible to save memory because using useCallback and useMemo prevents creating the function and variable again and again by saving and reusing the previous result, as long as a state inside the dependency array is not changed during the component re-rendering.
So far, this was my answer. But the interviewer said useCallback does not prevent creating a function. Even if useCallback is used, a function is still created.
I do not get this part. How is the function created again inside the useCallback hook?
Is there something I'm missing about useCallback and useMemo?...
ANSWERAnswered 2021-Sep-02 at 12:56
In the example bellow:
useCallback will prevent newly
changeWithUseCallback re-create every new render, result that
Child1 never gets re-render because it's props (changeWithUseCallback) never re-created.
Otherwise, in the
Child2 component, its prop (changeWithoutUseCallback) is always re-created during renders, so the component itself will re-render.
Please note that React.memo will skip rendering the component if its props have not changed
So I would say that you are right about
useCallback that it will keep the function/variable reference during renders, or
prevent creating new function/variable during renders.
Post API format...
ANSWERAnswered 2021-Sep-01 at 08:31
This is a matter of async function. It returns
promise object (refrence):
Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise.
makePostRequest is async function there is a need to use some asynchornous construction, like
await, to get the results.
I think the easiest should be to correct
reply assignment and flowing lines to :
return statment added to aviod
Error: No rersponse has been sent
This is a problem I was asked to solve during an interview, but the code I implemented during interview cannot pass all test cases, the problem is just as title said, given N and T (T >= N), which are initial floor and target floor respectively, one can move to current floor + 1, current floor - 1 or 2 * current floor in one minute, what's the minimum time need to reach the target? I think it's a typical DP problem, this is how I did in interview...
ANSWERAnswered 2021-Aug-05 at 14:41
An easy way is to start from the target
T and to found how many iterations we need to go down to initial value
N. Here, the allowed operations are +1, -1 and division by 2.
The key point is that division by 2 is only allowed for even value of
T. Moreover, if
T is even effectively, then it seems clear that division by 2 is the road to take, except if
T is near enough to
N. This little issue is solved by comparing
1 + nsteps(N, T/2) with
T - N.
T is odd, we must have to compare
nsteps(N, T-1) with
Last but not least, if
T is less than
N, then the number of steps is equal to
N - T.
Here is a simple C++ implementation to illustrate the algorithm. It should be easy to adapt it in any language.
I recently came across an interview question which although had an immediately obvious solution, I struggled to find a more efficient one.
The actual question involved counting numbers from
b (up to
2^64) which satisfied having either the digit
8, but not both. They called it a 'lucky number'. So for example:
ANSWERAnswered 2021-Jun-30 at 03:55
I would say you are at the right track. The gut feeling is that dealing with the
b separately is easier. Making a function
I'm using Active Job with sidekiq adapter in Rails 22.214.171.124
Strangely, custom service singleton methods are lost when they're called in Active Job.
ANSWERAnswered 2021-Jul-06 at 07:01
Seemed like it was an issue with zeitwerk autoloading mode which was introduced as default in Rails 6
I temporarily opted out in config/environments/production.rb:
No vulnerabilities reported
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page