CareerCup | Cracking The Coding Interview学习记录(C语言实现)
kandi X-RAY | CareerCup Summary
kandi X-RAY | CareerCup Summary
Cracking The Coding Interview 刷题记录.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CareerCup
CareerCup Key Features
CareerCup Examples and Code Snippets
Community Discussions
Trending Discussions on CareerCup
QUESTION
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?
...ANSWER
Answered 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
QUESTION
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?
...ANSWER
Answered 2018-Oct-18 at 08:41Many 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 ADDRESS
(0x2000
) there seems to be stored a pointer to a structure of type VEC
.
With (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 VEC
.
QUESTION
I have a list of points: [(x, y), (x, y), (x ,y) ... (x, y)]
.
I want the k
nearest points to (0, 0)
.
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?
ANSWER
Answered 2018-Mar-10 at 15:24Since you're already using heapq, you might as well use the nsmallest
function instead of reinventing it:
QUESTION
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:
...ANSWER
Answered 2018-Apr-08 at 19:58I 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:
QUESTION
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
...ANSWER
Answered 2018-Mar-06 at 13:16You 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 O(1)
, 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.
QUESTION
At careercup site, there was this problem (https://careercup.com/question?id=6270877443293184):
...ANSWER
Answered 2018-Feb-01 at 20:55You are right, in the worst case this is not O(n^2)
.
The author obviously assumed that list
from 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 std::map
(or TreeMap
in Java) because with std::map
just the find
operation is O(logn)
.
QUESTION
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.
ANSWER
Answered 2018-Jan-31 at 13:54Here is a synchronized instance method:
QUESTION
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):
...ANSWER
Answered 2017-Feb-16 at 17:57It 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 k
calls.
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.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CareerCup
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page