kandi X-RAY | CareerCup Summary
kandi X-RAY | CareerCup Summary
Cracking The Coding Interview 刷题记录.
Top functions reviewed by kandi - BETA
CareerCup Key Features
CareerCup Examples and Code Snippets
Trending Discussions on CareerCup
I was looking at the code for how to remove duplicates from a list and I came upon some syntax I am unfamiliar with. What does $1 ++ $0 mean?...
ANSWERAnswered 2020-Apr-13 at 18:36
$0 is the first parameter passed into the closure.
$1 is the second parameter.
++ is a custom infix operator
Before I asked I have research similar question. The most closet is this: https://www.careercup.com/forumpost?id=5752438032171008
But I still don't understand, what is the meaning of this code?...
ANSWERAnswered 2018-Oct-18 at 08:41
Many hardware systems have memory mapped registers, places where they store or read data. On small embedded direct-to-hardware systems it's common that those registers are placed in fixed locations, i.e. addresses.
What the macro does is basically allow access in a nicer way to such a location, instead of having to write all the casting and dereferencing each and every time.
More specifically, on the location of
0x2000) there seems to be stored a pointer to a structure of type
(unsigned int*)ADDRESS the macro pretends that the value of
ADDRESS is really a pointer to
unsigned int. The macro then dereference that pointer, to get the value stored in memory at
ADDRESS. Lastly, this value is then converted to a pointer to
I have a list of points:
[(x, y), (x, y), (x ,y) ... (x, y)].
I want the
k nearest points to
I'm trying to implement something like in this link. However, I am implementing the algorithm incorrectly, and I'm not sure where it's going wrong. I think perhaps
heapify doesn't know how to maintain order between points. How can I solve this?
ANSWERAnswered 2018-Mar-10 at 15:24
Since you're already using heapq, you might as well use the
nsmallest function instead of reinventing it:
The problem is as follows: we want to build a wooden board composed of exactly k planks. We're given two types of planks: shorter and longer. How to determine all possible lengths of such a board?
The solution to this problem can be found here.
The pseudocode is:...
ANSWERAnswered 2018-Apr-08 at 19:58
I think you are misunderstanding the question. The algorithm never takes into account how many of each type of plank you have, only that you have various lengths to choose from. So if you call the function:
I am trying to understand space complexity of the following piece of code. The code compresses Strings from "aabbbb" to "a2b4". The question is Question 5, Chapter 1 from Cracking the coding interview version 5 (2013) and the code is taken from the solutions...
ANSWERAnswered 2018-Mar-06 at 13:16
You are asking about the space complexity of
compressBetter, which includes a call to
countCompression, but also performs additional work.
While the space complexity of
countCompression is indeed
compressBetter has linear space complexity (i.e.
O(N)) in the worst case (where no two consecutive characters of the input
String are equal), since it produces a
StringBuffer of 2N characters in that case.
At careercup site, there was this problem (https://careercup.com/question?id=6270877443293184):...
ANSWERAnswered 2018-Feb-01 at 20:55
You are right, in the worst case this is not
The author obviously assumed that
map> would contain only few members; it is the assumption similar to the one that we use when we state that the complexity of
find operation of a hash table is
O(1). Recall, a hash table whose collision resolution is based on separate chaining has a constant complexity of
find operation on average, but in case when many elements hash to the same value it can degrade to a linear complexity.
Implementation-wise, notice that map
map> needs to be a hash table (i.e.
std::unordered_map in C++,
HashMap in Java), not
TreeMap in Java) because with
std::map just the
find operation is
Given the below mentioned code and suppose that we have two different threads thread1,thread2 as well as two different objects p1 and p2 of the class BCell.
If thread1 executes
p1.swap(p2) and thread2 executes
p2.swap(p1) simultaneously what is a possible problem that may occur?
I have already read here and here but it didn't seem to help.
ANSWERAnswered 2018-Jan-31 at 13:54
Here is a synchronized instance method:
Given the question here. https://www.careercup.com/question?id=9406769 which asks: Given two unsorted int arrays, find the kth element in the merged, sorted array. k element in an index that starts at 1.
What would be the BigO performance of the solution below (prints 1):...
ANSWERAnswered 2017-Feb-16 at 17:57
It takes O(n) time to build the heap, and it requires O(n) extra space.
Finding the kth item is O(k log n) Each call to
minheap.dequeue requires O(log n), and you're making
This approach works if you have enough memory to hold everything in memory. If you don't have enough memory, say you're doing this with two absolutely huge files, then the process is slightly different. See Time complexity of Kth smallest using Heap.
No vulnerabilities reported
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page