Classic string manipulation interview questions? [closed] - string

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am scheduled to have an onsite interview so I am preparing few basic questions. According to the company profile, they are big on string manipulation questions. So far I have manually coded these functions:
String length, copy, concat, remove white space
Reverse
Anagrams
Palindrome
Can someone give me a list of more classic string questions which I can practice before going there?

They might ask you about regular expressions. If they are using Java, they might ask the difference of StringBuffer and StringBuilder.

Reverse words in a sentence, e.g.
"string manip interview question"
becomes
"question interview manip string"
this has a solution that uses only one char worth of temporary space.

Make sure your reversal is in-place. You didn't state, so perhaps it already is.
Asking you to re-implementing strstr() or strtok() might be up their alley too, I guess.
UPDATE: As a bonus, if you do end up re-implementing either of those, remember to not name your functions starting with str, since that namespace is reserved. Having a candidate display that knowledge in an interview would impress me, at least. :)

Fast search like Boyer-Moore and Knuth-Morris-Pratt. Fast strlen by examining more than one byte at a time. Simultaneously finding multiple strings in a large body of text with Rabin-Karp. Finding nearest matches with things like Levenshtein distance. Regular expressions and how they might implement parts of it. Various unicode and other multibyte string encodings and how to convert between them.

Design a regular expression library.

Check this out. Might not fit the description for 'classic', but very interesting.

I'd look up string algorithms in a good algorithm book. For example, the Boyer-Moore algorithm, Tries, Suffix Trees, Minimum Edit Distance, stuff like that.

Related

Classes with reserved names (keywords). How do you deal with this? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
it just so happens that my class is a (Medical)Service, do you have any suggestions on what I would name a Service in angular that retrieves medical services?
So far I have thought of two things:
MedicalServicesService sounds a bit weird or not?
I was thinking of maybe replacing "(medical) service" by a synonym, maybe "medical assistance". Then I would have MedicalAssistanceService as the (programming) service name.
Still, surgery hardly passes for a medical assistance. It really is a medical service.
Was curious what people do when one of their classes names just happens to use a programming keyword. A question open for debate.
Not sure if naming conventions questions are allowed here? I will gladly delete my question if they aren't. Thank you.
First off, this depends a lot of the language.
TALK TO YOUR TEAM
Secondly, and most important! Conventions may change a lot depending on your team. Talk to your team, and agree on one convention to use. Never forget this.
Conventions
There are universal conventions/standards to follow, and like you mentioned, using keywords is usually a bad-ish idea. I for one try to avoid them, just as I avoid using digits in my variable-names, even if the specific language I'm working with allows it. Reason? It's easier to stick with "let's avoid problems by mixing rules between languages" than having to check the rules each time.
I often spend 30 minutes thinking of the perfect variable name, so I am quite used to this kind of pondering.
Length
Excessively long variable names is bad, because it hinders flow reading, while excessively short variable names are also bad because it is hard to guess what word you want. You could call it srvc, sure, but who will know what that means in a month (unless you comment it, sure). Dropping the vowels in user-variables is quite common, actually, especially in low-level/old languages.
Specific case
As for this specific example, I wouldn't think of MedicalService as a keyword. First off, it's part of a longer name, like MedicalFile doesn't look like a file from the system at all, but rather a form with medical data on it.
I don't exactly know what this MedicalService does, but it seems like a generic (abstract, probably) class name for services that you can ask for at the counter of a hospital, so I'm assuming that.
GenericMedicalThingToDo is a funny way to avoid the keyword, but I wouldn't call it that. MedicalUseCase seems quite better, and gets to the point.
On the other hand, if this is just a string stating the use case for whatever it is the user has chosen (considering you mentioned Angular), I would just stick with userMedicalChoice (drop the PascalCase to camelCase).
If you need to use a word that is actually a keyword, which often happens, you might want to add a _ on the end or the beginning of it. This is not usually good for interfaces, as it's conventional to only use those internally/privately. Some conventions use double _ for private, and single _ to avoid dupes.
Last point:
Having keywords as part of a longer variable name is not a problem in any of the many programming languages I have sailed in, so just call it MedicalService, or GenericMedicalService if you're going to subclass it.
PS: Read up on some conventions of different languages, like PEP-8, and PEP-256 from Python, or Google's C++ conventions. While not specifically being valid for all languages, they do give you something pin-pointers to what is important.

What is the reason that the designers of Rust chose the symbols !/&&/|| instead of the words not/and/or? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
What was the rationale used for choosing the operators !/&&/|| over not/and/or? Is there some history behind it, or was it just a preference thing?
Some ideas I've had:
Rust followed C / C++. However, in the case of for-each loops, the more English-like version of for x in X is used instead of C++'s for (x: X), so Rust didn't just blindly follow C / C++ in everything.
The symbols are shorter. The number of characters seems similar between the two.
The syntax had to be different due to a collision with type-specifications. There is also difference of a as u8 instead of (u8)a.
Since Rust is a new language, I would think that they could choose either symbols or words without issue. What is the reason Rust chose symbols over words? Why did it not choose both?
Back in 2006, Graydon Hoare started working on Rust as a small project. Hoare also worked on the Servo browser engine. His goal for Rust was that it might help with the development said browser engine. Since the engine (like almost all other browser engines) was written in C++ at that time, Rust was basically a C++ replacement for Hoare.
So using the same logical operators as C++ seemed just natural.
When the GitHub repository was created in 2010, && and || were already in the Rust language. See the lazy-and-or.rs test during the second commit in the repository:
if (true && x) { ... }
Over time, the language design process got a lot more democratic and a lot more ideas appeared. But it wasn't until 2016 that someone officially proposed adding not, and and or as an RFC.
But as you can see the RFC was closed. The contributor withoutboats explained it like this:
If I were designing a language from the beginning, I would probably prefer and and or. But we are generally opposed to contextual keywords unless absolutely necessary, contextual keywords in expression contexts are particularly difficult to introduce, and we tend to avoid syntactic sugar of the "pick your poison" variety.
It is important that at that point !, && and || were already been stabilized for more than a year. So the only option was to add alternative operators, but not replace those ones. That didn't seem worth it.
Disclaimer: I only joined the Rust community in 2014. There might have been larger discussions about this in IRC or other media I can't search. But this is all I could find.

C style Scripting language [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to develop a simple C style scripting language for educational purposes.
Thing I have done so far:
defined syntax of the language
written code for tokenizing the language.
The features that I want to include at the moment:
Arthematics
Conditions
while loop (only)
At the moment I don't want to add other features to the language, as it will make development procedure quite complex.
However, I don't know what are the next steps that are involved in developing a language. I have gone through many questions on SO but they weren't very specific in detail. Kindly guide me with this process.
I think these answers are helpful starting out:
How to go about making your own programming language
How to develop Programming language like Coffee script?
If you have defined a EBNF grammar, then you can use a tool like BISON to create a parser. Using that parser to generate an abstract syntax tree you can then proceed to create an interpreter for your language.
Few years back I have been developing my own language too (it was interpreted language) and in phase when language was ready for "others" to try, I found out that there were few things I should have done earlier, or better:
Solve tons of simple programming problems in that language
Solve just a few, but I would call it "hard core" programming problems with it (for example Project Euler)
Write complex language specification, few examples, wiki or FAQ, well anything that will spare you answering the same questions all the time
Hope that helps.
Yes, having done this several times I know it's hard to know where to start. And you really don't need Lex or Yacc or Bison.
Make sure you have the definitions for your lexical elements (tokens) and grammar (in EBNF) nailed down.
Write a lexer for your tokens. It should be able to read a sample program emitting tokens and ending gracefully.
Write a symbol table. This is where you will put symbols as you recognise them. You can put reserved words and literals in here too, or not. It's a design choice.
Write a recursive descent parser, with a function for recognising each production in your grammar. You may need to modify your grammar to let you do this.
Write a tree/node manager for your AST (Abstract Syntax Tree). The parser adds nodes to the tree with links into the symbol table as it recognises productions.
Assuming you get this far, the final two steps are:
Walk the AST performing type and reference resolution, some kinds of optimisation, etc.
Walk the AST to emit code.
The last two steps turn out to be where most of the hard work is.
You will needs some specific references and what you choose depends on your level and what you like to read and what language you like to write. The Dragon Book is an obvious choice, but there are many others. I suggest you look here: Learning to write a compiler.

Haskell monad: etymology versus meaning? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When I'm developing an understanding of some concept, I find it very unsatisfactory not to be able to see how the apparent etymology of the concept name relates to what I think I'm understanding about the concept. If I can't see the connection, I'm left with the feeling that there's some significant insight the name is trying to convey that I haven't yet discovered.
Monad: From Greek for unity. Mon = one; ad = a group or unit comprising a certain number. This composes to "A group or unit composed of one thing".
http://www.haskell.org/haskellwiki/All_About_Monads says:
"A monad is a way to structure computations in terms of values and sequences of computations using those values. Monads allow the programmer to build up computations using sequential building blocks, which can themselves be sequences of computations." ... "Other monads exist for building computations that perform I/O, have state, may return multiple results, etc"
Nothing much there about one-ness.
http://www.haskell.org/haskellwiki/Monad claims that the one-ness in term monad refers to the one output that a monad will produce. But given that any function produces one output, (and the above reference says "may return multiple results", not to mention out-of-band/error results), and there's nothing about the "group or unit", that explanation seems unconvincing.
Is there some better explanation?
[Edit: Responding to the "off topic" flag. My question is not about the etymology of the word "monad" per se. It is about the Haskell concept of monad, and how the roots of the word monad do or do not inform us about that concept, or perhaps actually misdirect us from understanding the topic. Given that monad is a famously hard-to-communicate concept in Haskell, this is certainly a question about programming.
That this is a salient issue is reinforced by the variation in respondent suggestions regarding how the roots in "monad" might relate to the topic at hand, including the observation that the explanation in Haskell's own documentation is highly suspect.
That said, I'm pretty satisfied with the answers given (thanks all!), so no need to reopen the topic. But I'd advocate not moving it elsewhere, so that others with the same confusion about an important Haskell concept can find it here.]
Is there some better explanation?
Short answer: No, there really isn't.
Slightly less short answer: It's almost certainly related to "monoid", and not related to any other use of "monad" (there are at least two), and the term was coined at a gathering of mathematicians so there's likely not even a written source that's the first use of the term.
Longer answer with quotes and citations: The one I wrote here.
That claim on the wiki about the alleged meaning seems very dubious to me, incidentally.

Letter O considered harmful? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Back in the day, the FORTRAN standards committee reviewed a technical proposal called "Letter O considered harmful". I used to be able to find a link to the text of this proposal on the net, but it seems to have disappeared since the last time I looked for it -- the link disappeared off the relevant Wikipedia page and the only Google hits for the term are references back to Wikipedia. Does anyone happen to know a good repository of information about FORTRAN so that I could track it down, or even better, have a link to the proposal itself?
You are indeed correct!
Yes, there was such a proposal (entitled "Letter 'O' Considered Harmful")
in the official set of documents supplied to voting members at the November 1976 meeting of X3J3 that was held at Brookhaven National Laboratory. (At this same meeting, committee chose "Fortran 77", with six lower-case letters, as the name for this revision of the language.)
I am able to verify this because I was not only the host for this meeting but also the actual author of this anonymous "proposal". As such, I enlisted the typist (my boss' secretary, Bette) to type up this phony "proposal" in the proper format and slip it into the official distribution provided at the meetingplace (Conference Room B of Berkner Hall).
Loren Meissner was so amused by it that he wrote a little item in a Fortran publication for which he was editor. Walt Brainerd also mentioned it in his publication. I had sworn both of them to secrecy regarding my little prank, so those articles did not identify me. (Sorry, I don't recall the names of these two publications.)
The lists of pro and con arguments (as was typical of X3J3 proposals in those days) included:
Restoring the number of Fortran characters to 48 (by omitting 'O'to counterbalance the addition of the colon ':')
Solving ambiguities caused by nested DO loops.
Eliminating problems with (deprecated) Hollerith specifications in FORMAT statements.
Preventing misuse of GO TO statements.
while the "con" list contained only one objection (with a disclaimer):
This proposal may invalidate some existing FORTRAN programs, but most of these are probably "standard-conforming" anyway.
I think this is the guy to ask: Bruce A. Martin. He seems* to be the one who originally posted it on Wikipedia, and he puts himself as working at Brookhaven (where the article was circulated) at the same time.
The citation he gives on Wikipedia for the article is:
X3J3 post-meeting distribution for meeting held at Brookhaven National Laboratory in November 1976.
(* the user page for the user that posted it links to the website as being their material)
Mentioned on Wikipedia, referred to as a joke / folklore. Doesn't surprise me TBH.

Resources