click here
www.twitter.com/freakyIdea
***Follow Us On Twitter***

Testimonials

Amazing Concept, some ideas from freaky idea could change the world for sure.--Kevin
Its an amazing site, some of the ideas are so practical that i use them in my daily life. It is also a great place for different kinds of weblinks from puzzles, movies, games, News, Education, IQ, etc Freakyidea toolbar is a must have toolbar - from FM channels, to weather to, games all bulit in One Toolbar. Outstanding is the word for the Site!!--Simran
Its been a real good place to put your freaky ideas and also read other people. I am really impressed by the freaky toolbar. It contains all what u need without googling for it :)--Ravi
I like the concept of Freakyidea. It helps give a vent to your creative side which at time get lost due to our systematic and mechanical life. Kudos to the teams--Jenny
The ideas on the site are nothing but amazing some are just so "FREAKY" :). Nice concept to re ignite your creative side.-Chenz
A place for real innovation as all invention could be back tracked to some really freaky idea or concept.It just promote that FREAKY Instinct.Thanks to whole team to again encouraging people to think out of box -- Kapil
Freaky Idea Team Helped me to start my business. THANK YOU FOR ALL YOUR HELP. -Dheeraj

Login

Submit your Creative Ideas by Signing in.



How to reverse the String PDF Print E-mail
Freaky Ideas - Puzzle
Written by Anita   
0.0/5 (0 vote)

A typical programming interview question is "reverse a string, in place". if you understand pointers, the solution is simple. even if you don't, it can be accomplished using array indices. i usually ask candidates this question first, so they get the algorithm in their head. then i play dirty by asking them to reverse the string word by word, in place. for example if our string is "the house is blue", the return value would be "blue is house the". the words are reversed, but the letters are still in order (within the word).

Solution:

solving the initial problem of just reversing a string can either be a huge help or a frustrating hinderance. most likely the first attempt will be to solve it the same way, by swapping letters at the front of the string with letters at the back, and then adding some logic to keep the words in order. this attempt will lead to confusion pretty quickly.

for example, if we start by figuring out that "the" is 3 letters long and then try to put the "t" from "the" where the "l" from "blue" is, we encounter a problem. where do we put the "l" from "blue"? hmm... well we could have also figured out how long "blue" was and that would tell us where to put the "l" at... but the "e" from "blue" needs to go into the space after "the". argh. its getting quite confusing. in fact, i would be delighted to even see a solution to this problem using this attack method. i don't think its impossible, but i think it is so complex that it's not worth pursuing.

here's a hint. remember before when we just reversed "the house is blue"? what happened?

 

initial: the house is blue reverse: eulb si esuoh eht 

look at the result for a minute. notice anything? if you still don't see it, try this.

 

initial: the house is blue reverse: eulb si esuoh eht wanted : blue is house the 

the solution can be attained by first reversing the string normally, and then just reversing each word.