String getRegularExpression(String str1, String str2);
Base on input 2 strings, return a regex String that can cover 2 input strings.
e.g “Bloomberg”, “BloomingDale” should output “Bloom.*g.*”
I proposed a solution:
step 1: find out common segments of the 2 strings
step 2: insert “.*” in between the common segments to form a string
He asked: how to find the common segments?
also he let me think of below examples, but I really couldn’t find any
clue from his example.
In the end, he said my proposed solution is not technically optimized.
Obviously, he has better solution, but he didn’t give me the hint.
So I still have no idea at all.
Can you think of a solution?
In one sample code (p190 [[c++in24hour]]), we see that once you delete a pointer, the reference to the object becomes a dangling reference. More common when multi-threaded.
I guess sometimes we do create a reference to a dereferenced pointer, but we have standard guards to avoid dangling references. What are these guards? Not sure.
Reference param is best practice in c++. What if caller passes an unwrapped pointer into a function’s ref param? How do you ensure the underlying heap/stack thingy doesn’t get deallocated?
– Single-threaded — if the pointee is accessible only on this thread, it can’t possibly “vaporize” beneath my feet. The caller won’t (technically impossible) delete the ptr before the func returns.
– multi-threaded — all hells break lose. We need guards.
There are many similar multi-threading “delete” issues to be solved with ownership control. Only one function on one thread should delete.
Here’s a common java swing memory leak as described on stack overflow — Essentially, because you register an object as a listener and forget to unregister, the notifier ends up holding onto the reference of the object, and leaks a bit of memory.
Same problem with c# events. [[effective c#]] refers to it as “runtime coupling despite compile-time loose coupling”. Recall an event
is a pseudo field in a class, and the fields’ type is a delegate, which is a list of 2-pointer constructs. First pointer usually points to a listener object. Imagine a bunch of large listener objects are added to the delegate’s inv list (registered for event), and one of them is no longer needed. You want its memory freed, but the event source object still holds a reference via the delegate instance. See [[effective c#]] item 23. One tip is to unregister in the listener’s Dispose()
I feel the dotnet event/delegate language construct has no exact java counterpart at the language level, but at runtime, swing event
paradigm == c# event paradigm. Fundamentally the same paradigm. Part of the paradigm is that the event source object holds a
collection of subscriber Objects. If the GUI stays up for 22 hours then the subscriber Objects are held “hostage” for that long, and
cannot be garbage collected.
I too get haunted by criticism, failed relationships (but not those sexual types;) with past coworkers, or my poor judgement and decisions in past projects.
Notes on Raymond Teo discussion: west coast shops … creating big value through high user base, high data, …..innovation is high risk — “risk premium”. In contrast, Singapore IT projects have a fixed “value” i.e. the project budget. ($1m is quite big.) Directly impacts IT salary.
Those “upstream” sectors often needs a smaller number of elite techies.The “upstream” don’t really exist in Singapore. Therefore, only a small elite of techies in Singapore would end up in the financial IT domain. The vast majority of techies live in a totally different world and earn S$60k (up to $100k) a year as non-managers.
As I stated elsewhere, an mediocre techie easily earn a Wall St salary on Wall St, but the same guy would earn $60k in Singapore.
Database/OperatingSys vendors enjoy highest margins (in silicon Valley) but no all Oracle clients get the same ROI buying oracle. Let’s compare the major client-industries that are using technologies. In which sectors does technology create the most profit? Note consumers are the largest user population of technology, but consumers don’t make profit and are not an “industry”, and (crucially) won’t pay us a salary. Our focus here is the major commercial sectors/industries using technology to make profit.
Telecom equipment makers make heavy use of technology and have good margin. Like the DB/OS creators, a small number of elite engineers create industry standards…. Anyway, here are a few sectors.
#1a) HFT or algo trading, either sell side or buy side
1a) other trading engines
2) risk engine, but is the calc really useful, relevant and accurate to be reliable?
2) settlement system can be just as critical and valuable to an i-bank
1b) search engine?
1b) facebook, linkedin, Amazon …
1c) DB/OS/language, as described above, is not a client industry, but DB/OS profit margin is higher than all other domains.
4) Telecom equipment maker, as described above
5) commercial banking, corporate/retail banking, insurance. Lower margin than trading, but higher than non-financial service industries. ecommerce like amazon, ebay…? I feel thousands of online services offer useful services but have low margin. B2B better than B2C.
telecom operators? I know a lot of operators (US or S’pore) don’t pay very high, partly because technology is at equipment makers. health care? logistics? no no no