EzDevInfo.com

language-agnostic interview questions

Top language-agnostic frequently asked interview questions

Getting the closest string match

I need a way to compare multiple strings to a test string and return the string that closely resembles it:

TEST STRING: THE BROWN FOX JUMPED OVER THE RED COW

CHOICE A   : THE RED COW JUMPED OVER THE GREEN CHICKEN
CHOICE B   : THE RED COW JUMPED OVER THE RED COW
CHOICE C   : THE RED FOX JUMPED OVER THE BROWN COW

(If I did this correctly) The closest string to the "TEST STRING" should be "CHOICE C". What is the easiest way to do this?

I plan on implementing this into multiple languages including VB.net, Lua, and JavaScript. At this point, pseudo code is acceptable. If you can provide an example for a specific language, this is appreciated too!


Source: (StackOverflow)

What is the difference between currying and partial application

I'm not exactly sure how to word this question.

I learnt what currying was in the first year of university, and have been using it where applicable ever since.

However, I quite often see on the Internet various complaints that other peoples examples of currying are not currying, but are actually just partial application.

I've not found a decent explanation of what partial application is, or how it differs from currying. There seems to be a general confusion, with equivalent examples being described as currying in some places, and partial application in others.

Could someone provide me with a definition of both terms, and details of how they differ?


Source: (StackOverflow)

Advertisements

How to write a good README

I guess everyone has seen a README file, but I would like the definitive guide on how to write an excellent README file with the least amount of energy spent on it.

  • What's a README file?
  • What should I write in it?
  • How exactly should I format it?

Side note:

As an example that satisfies "OMG this is an excellent README!" and "OMG this README is useless", I posted a link to gnome-cups-manager's README as a comment. The comment is now removed probably due to dead link so I copied the content to this gist.


Source: (StackOverflow)

Should a function have only one return statement?

Are there good reasons why it's a better practice to have only one return statement in a function?

Or is it okay to return from a function as soon as it is logically correct to do so, meaning there may be many return statements in the function?


Source: (StackOverflow)

What is the difference between a deep copy and a shallow copy?

What is the difference between a deep copy and a shallow copy?


Source: (StackOverflow)

Concurrency vs Parallelism - What is the difference?

Concurrency vs Parallelism - What is the difference? Any examples


Source: (StackOverflow)

Database, Table and Column Naming Conventions? [closed]

Whenever I design a database, I always wonder if there is a best way of naming an item in my database. Quite often I ask myself the following questions:

  1. Should table names be plural?
  2. Should column names be singular?
  3. Should I prefix tables or columns?
  4. Should I use any case in naming items?

Are there any recommended guidelines out there for naming items in a database?


Source: (StackOverflow)

What does it mean to "program to an interface"?

I have seen this mentioned a few times and I am not totally clear on what it means. When and why would you do this?

I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly.

Is it just so if you were to do:

IInterface classRef = new ObjectWhatever()

You could use any class that implements IInterface? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed expect for it implementing IInterface. I cannot think how often you would need to do that... (Also, how could you write a method that takes in a object that implements an interface? Is that possible?)

Sorry if I completely missed the point.


Additional questions:

  • does using an Interface hit performance?
  • if so how much?
  • how can you avoid it without having to maintain two bits of code?

Source: (StackOverflow)

Performance optimization strategies of last resort [closed]

There are plenty of performance questions on this site already, but it occurs to me that almost all are very problem-specific and fairly narrow. And almost all repeat the advice to avoid premature optimization.

Let's assume:

  • the code already is working correctly
  • the algorithms chosen are already optimal for the circumstances of the problem
  • the code has been measured, and the offending routines have been isolated
  • all attempts to optimize will also be measured to ensure they do not make matters worse

What I am looking for here is strategies and tricks to squeeze out up to the last few percent in a critical algorithm when there is nothing else left to do but whatever it takes.

Ideally, try to make answers language agnostic, and indicate any down-sides to the suggested strategies where applicable.

I'll add a reply with my own initial suggestions, and look forward to whatever else the Stack Overflow community can think of.


Source: (StackOverflow)

Understanding "randomness"

I can't get my head around this, which is more random?

rand()

OR

rand() * rand()

I´m finding it a real brain teaser, could you help me out?

EDIT:

Intuitively I know that the mathematical answer will be that they are equally random, but I can't help but think that if you "run the random number algorithm" twice when you multiply the two together you'll create something more random than just doing it once.


Source: (StackOverflow)

What is tail recursion?

Whilst starting to learn lisp, I've come across the term tail-recursive. What does it mean?


Source: (StackOverflow)

Prefer composition over inheritance?

Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition?


Source: (StackOverflow)

Is floating point math broken?

0.1 + 0.2 == 0.3
-> false
0.1 + 0.2
-> 0.30000000000000004

Any ideas why this happens?


Source: (StackOverflow)

What is dependency injection?

There have been several questions already posted with specific questions about dependency injection, such as when to use it and what frameworks are there for it. However,

What is dependency injection and when/why should or shouldn't it be used?


Source: (StackOverflow)

Pair socks from a pile efficiently?

Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and "iterating" the pile in order to find its pair. This requires iterating over n/2 * n/4 = n2/8 socks on average.

As a computer scientist I was thinking what I could do? Sorting (according to size/color/...) of course came to mind to achieve an O(NlogN) solution.

Hashing or other not-in-place solutions are not an option, because I am not able to duplicate my socks (though it could be nice if I could).

So, the question is basically:

Given a pile of n pairs of socks, containing 2n elements (assume each sock has exactly one matching pair), what is the best way to pair them up efficiently with up to logarithmic extra space? (I believe I can remember that amount of info if needed.)

I will appreciate an answer that addresses the following aspects:

  • A general theoretical solution for a huge number of socks.
  • The actual number of socks is not that large, I don't believe my spouse and I have more than 30 pairs. (And it is fairly easy to distinguish between my socks and hers; can this be used as well?)
  • Is it equivalent to the element distinctness problem?

Source: (StackOverflow)