How to reverse a sentence without additional memory [duplicate] - algorithm

This question already has answers here:
Reverse the ordering of words in a string
(48 answers)
Closed 9 years ago.
I was recently asked this question in an interview.
Initially, I was asked to reverse a sentence without using inbuilt String api methods like split etc.
I/p : I like god
O/p : god like I
I did this using a stack. His next question was to accomplish this without using additional memory.
How do we achieve this in java?
Thanks!

Reverse the sentence in-place on a character-by-character basis, then reverse each word in the sentence in-place on a character-by-character basis.

Related

How to efficiently match hundred thousands of substring in one string using elasticSearch [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 6 years ago.
Improve this question
My problem is simple: I have a database containing 400,000 substrings (movies and tv shows titles).
I'd like to match these titles in a message such as:
I really love Game Of Thrones and Suits, also Spotlight is an awesome
movie.
What I need is to match Game Of Thrones, Suits and Spotlight in this string.
I tried to send all titles to wit.ai but it seems that it can't handle 100,000 substrings.
I'm wondering if elasticsearch could do the job?
If that's a common problem, sorry, could you help me to search in the right direction.
Thanks!
One of the best algorithms to find strings from dictionary in a text is Aho-Corasick one
dictionary-matching algorithm that locates elements of a finite set of
strings (the "dictionary") within an input text. It matches all
strings simultaneously. The complexity of the algorithm is linear in
the length of the strings plus the length of the searched text plus
the number of output matches.
But I wonder that your database engine does not provide possibilities for such searching... Probably it really can, but you don't know?

Python : Which Sort Method is used behind .sort()? [duplicate]

This question already has answers here:
What algorithm does Python's built-in sort() method use?
(2 answers)
Closed 7 years ago.
I have always heard that usually merge sort is used for in built functions. But I cannot understand why. Quicksort is faster obviously with exact time complexity of 1.39NlogN and also it is in place! then why not quick sort?
timesort algo is used in the inbuilt sort

In- place quick sort - Ruby [duplicate]

This question already has answers here:
Quick Sort in Ruby language
(6 answers)
Closed 7 years ago.
I'm having trouble wrapping my head around a in-place quick sort. I understand it using sub-arrays, but in-place is really throwing me.
Having an example in Ruby would really help, but I haven been able to find one. Could some one provide me with an example or point me in the right direction?
Rather than trying to understand it in code, there's a number of very elegant explanations of the quicksort algorithm out there. Here are a few of my favorite illustrations which may help your understanding.
With cups
With Hungarian Dance
As for a Ruby example, the answers to this question cover that.

What is the difference between ".scan" and ".split" in Ruby language? [duplicate]

This question already has an answer here:
Difference between String.scan and String.split
(1 answer)
Closed 9 years ago.
What is the difference between ".scan" and ".split" in Ruby language?
Can someone give me an example?
i am really got confused about it!
scan extracts substrings that match the given regex.
split extracts substrings that do not match the given regex (and optionally, substrings that match as well).

Can someone explain the QR-Code image generation/encoding algorithm by example? [duplicate]

This question already has answers here:
Encode algorithm QR-code
(4 answers)
Closed 4 years ago.
Right now I am working for development of qrcode algorithm for past time project.
Can someone explain the main principle of this algorithm with example?
As an example, I'd like to convert the simple statement "I love StackOverflow" into a matrix representation of a qr-code.
If you really want to understand the encoding, you really need to buy the ISO specification (18004:2006). Nothing else will give you full detail enough to implement encoding.
Of course you can also look at source code implementing QR code encoding, if that's all you need. See zxing.

Resources