On an occasion i had a file with words listed one by one and i wanted to sort the file in lexicographic order. Since i work in linux machines , its just 1 command . `cat filename | sort ` to sort it in lexicographic order. But i wanted to do it in c++.  I tried googling for suggestions and found out that radix and bucket sort would help me out. And then i tried implementing the concept of Radix MSD to arrive the result. Sharing the code. I have added inline comments in the program. Hope it helps  (Note: i just wanted to arrive with the solution.. Not much concerned about efficiency of the program :-))

#include <iostream>
#include <map>
#include <vector>
#include <fstream>

using namespace std;

int main()

	vector<string> words;

	map<char,vector<string> > bucket;
	map<char,vector<string> > ::iterator it;
	vector<string> tempVec;

	// initializing map with null vector and empty for variable length string
	bucket[' '] = tempVec;
	char ch;
	//for(int i=97; i<123; i++)
	for(int i=65; i<91; i++)
		ch = i;
		bucket[ch] = tempVec;


	/*cout << "init" << endl;
	  for(int k=0; k<words.size(); k++)
	  cout << words[k] << "  ";
	  cout << endl;*/

	// finding the maximum character
	int max = 0;
	for(int i=0; i<words.size(); i++)
		max = (max > words[i].length())?max:words[i].length();

	// loop from max char till first char 
	for(int i=max-1; i>=0; i--)
		//cout << "Running for Phase " << i << endl;
		// loop through the entire vector
		for(int j=0; j<words.size(); j++)
			string word = words[j];
			int temp_len = word.length();
			// there may be possibility that word boundary is less than max
			if(temp_len < i)
				// push into the "" bucket
				//cout << "Pushing " << word << " into bucket " << "[empty]" << endl;
				bucket[' '].push_back(word);
				// index exists .. Hence check the char
				char temp_char;
				temp_char = word[i];

				// insert into map with temp_char, word
				//cout << "Pushing " << word << " into bucket " << temp_char << endl;


		// end of this loop, all the words are inserted into corresponding buckets
		// clear the input vector -- because we are going to change the order

		// iterate through the keys and write the order into input vector
		for(it=bucket.begin(); it!=bucket.end(); it++)
			tempVec = it->second;
			for(int k=0; k<tempVec.size(); k++)


		/*cout << "After bucket insertion words are  " << endl;
		  for(int k=0; k<words.size(); k++)
		  cout << words[k] << "  ";
		  cout << endl;

		// now we have the correct order of the phase .. hence clear the bucket
		for(it=bucket.begin(); it!=bucket.end(); it++)

		//cout << endl;

	cout << "Answer is " << endl;
	for(int k=0; k<words.size(); k++)
		cout << words[k] << endl;

	return 0;

1. Read the words and push into vector
2. find the max value by iterating the vector and finding length of all words
3. Iterate from max to 0
4. take each words first letter and push into corresponding bucket
5. Iterate through the buckets and save it as input word list order
6. After 0th Iteration , input vector will have the result.


step – 1
words pushed into vector

jump, sit, carry, run, site , runner

step – 2

finding the maximum length string
it would be runner – 6

step – 3

Iterating from index 5 to 0

Note : if the word length is less than index , we need to push in empty bucket(‘ ‘)

‘ ‘ – jump,sit,carry,run,site
r – runner

Hence, array order will be – jump, sit, carry, run, site


4th index of the words carry and runner are [y] and [e]

‘ ‘ – jump, sit, run, site
e – runner
y – carry

Hence, array order will be – jump, sit, run, site, runner, carry


3rd index for the words jump, carry, site, runner [p],[r],[e],[n]

‘ ‘ – sit, run
e – site
n – runner
p – jump
r – carry

Hence array would be sit, run, site, runner, jump, carry


2nd index for the words sit, run , site, runner, jump, carry are [t],[n],[t],[n],[m], [r]

m – jump
n – run, runner
r – carry
t – sit, site

Hence array would be jump, run, runner, carry, sit, site


1st index for the words jump, run, runner, carry, sit, site are [u],[u],[u],[a],[i],[i]
a – carry
i – sit , site
u – jump, run, runner

Hence array would be , carry, sit, site , jump, run, runner


0th index of the words are [c], [s], [s], [j], [r], [r]

c – carry
s – sit, site
j – jump
r – run, runner

Hence OUPUT : carry, sit , site , jump, run, runner

Good bye wake me up

Posted: November 19, 2014 in Health
Tags: , , ,

Are you the kind of person who keeps almost 10 to 15 alarms in your phone just to get up in the right time?

Are you the person to snooz alarm 5 to 10 times before getting up?

Forget it. . Thinks have changed.

Have you ever heard this quote “if you wanna get up in first alarm, just keep the alarm  clock away from your bed”

Now an android app made it real. From now there is no wake up alarm for us . Only we have a

You can keep the phone near the bed , but once the alarm triggers it can be switched off only if you walk ten steps with your phone. Otherwise it ll be keep ringing.

I personally tried it today and i got up in the first ring . Thank you walk me up team for a great innovation.

 “Are we really utilizing our time EFFICIENTLY ?”

Yesterday i watched “the last lecture” video by Mr. Randy Pausch that triggered few things in my mind. Do we really know , what we will be doing tomorrow 5.30 . Atleast, do we plan for that. For majority of us, answer is no. Atleast, for me !!!

After watching the video, i thought of finding a way through which i could find the golden time that am wasting through outt my life. Simple google search on apps lead me to 2 important android apps.

1. Routinely – https://play.google.com/store/apps/details?id=com.braavos.apps.routinely&hl=en

2. Schedule Planner – https://play.google.com/store/apps/details?id=com.intersog.android.schedule&hl=en

For ios users we have daily routines app which does the same stuff.

Firstly, the app routinely helps us to decide on what are all the things that we really need to do on daily basis . Hence, we can come up with our own list and check it up after completing it on day to day basis.

Second one is quiet interesting. Schedule Planner app helps us to list our stuff by dividing into categories. There are two tabs. Planned and Actual. You can plan your work, and you can move it to actual after performing it. In the pro version, we can edit our categories. Using this app for 1 week, we can easily find out on how we are wasting our time. and how we can manage it on useful stuff.

I could really see some changes in my learning process. You can try and share your comments as well.

It was a dream for me to learn 3 x 3 blindfold. Since , i was not good in memory skills , i thought it would never happen. But , after watching this video, everything changed and i learnt blindfold in a day .

Just in case, if you dont get a good clarity after seeing Zane C’s Video , i would really recomment to watch Badmephisto video given below

Since there are plently of methodologies covered in the video , i would like to stress more on the memorization part. Initially, the memorization part will take more time than to solve the pieces .

There are many ways through which you can memorize the piece orientation. People who are good in memory , use visual memory to memorize the pieces. But, visual memory wont last for a long time. And , it really needs good memory to remember all piece orientations.

Some People use objects to remember each piece. Even for this, we need a good memory because there will be around 15 to 20 object we need to remember with a connection.

Especially for the people like me, the third method is so suitable . We will label each piece with a Letter. Starting from UB as A we will move anti clockwise . In this case , you need not remember all the labels initially,

UB – A
UL – B
UF – C
UR – D

FU – E
FL – F
FD – G
FR – H

RU – I
RF – J
RD – K
RB – L

BU – M
BR – N
BD – O
BL – P

LU – Q
LB – R
LD – S
LF – T

UF – U
UL – V
UB – W
UR – Y (Not X , because we can form more words in Y than X )

For the initial solves, its fine to remember only 6 pieces

UB – A
FU – E
RU – I
BU – M
LU – Q
UF – U

From these pieces, we can appropriately move in anti clockwise direction and increase the alphabet .

Similarly, we can do it for Corners :


Hence, we just need to remember a letter , rather than remembering the position.

And also, once you form sequence of letters , we can form words with it. For Ex:

C D L M T S W can be randomly made as

CoDe LiMiT SoftWare (am a CS Engg :P)

Hence, we can simply say :

2 sentences = a blind fold solve.

All we need is to move one piece at a time and create words with the corresponding notation.

Very new to python Programming . I tried installing python 2.7 in my linux machine (ubuntu). Unfortunately , python 3 was already installed in the system.

For parsing the twitter tweets using python, i had to install oauth2 in my machine. i spent almost 2 to 3 hours doing it . Got almost 5 different kind of packages from internet and tried installing it.

Also installed additional libraries. PIP and all stuffs . But still, it didnt work. I got the same error as below

Traceback (most recent call last):
File “twitterstream.py”, line 1, in
import oauth2 as oauth
ImportError: No module named oauth2

At last , i found that the error was occuring because of the 2 differnt python versions in my system.

Then i started locating python directory and checked where it is pointing to. when i checked /usr/bin/python , it was pointing to python 2.7.

Instead of running the script as

python script_name.py

i changed it to

/usr/bin/python script_name.py

And yes, it worked. Sometimes we complicate few easy stuffs :-)

As the days are passing , computers are getting faster and faster . At the same time, the amount of data that is being used is growing exponentially. Hence, we are in a path of finding how to handle, store and analyze the huge data set in a effecient manner.

One among such example is Google Books Ngram . if you just navigate to the following URL

Google Books

you will be seeing a text box asking you to enter a book name. And it will search from 5.2 million books.

Believe it or not, Google has digitized all 5.2 million books and has come up with the concept of NGRAM.


This link will show you a default page like .

Google Books Ngram

Before getting into the page description , we need to know what is ngram . N-gram is a word in which , N is the number of times the word is being used in the books between selected years .

In graph , by default it shows the output of 3 different names, Sherlock Homes, Albert Einstein , Frankenstein . It go searches in 5.2 Million books and yields a graph with the N-gram count, which can tell you the exact amount of time the word is being used in the books on those specific years.

Even the data set is available to download and research . These kind of data analysis is used for prediction and other purpose. It yields interesting results when analyzed with selective phrases.

If your target is JUST to learn how to solve rubik cube, then the whole journey is going to be very simple . There are plenty of tutotials out there , which can help you to solve Rubik . BUT, if you are planning to be a speed cuber who can solve rubik in mere seconds then, this post is dedicated for you . I have categorized things into steps . Hope it would be helpful .

Step 1 : First Challenge is to get a good Rubik Cube :

I am not sure if am using the world’s best rubik cube, but i can assure you that you can really solve faster when you use Moyu Weilong

Step 2 : Getting Started – Pick a Method to solve

I solve rubik with Fridrich method (CFOP) . I never tried any other rubik Method , because i feel this method works really well for me . I would recommend watching this you tube tutorial which solves rubik in beginner method .

At the end of this video , you should be knowing how to solve a rubik cube . And you will be wondering How fast can i do this. Move on to Step 3 .

Step 3 : Dont get Greedy – Practice hard

Beginner method is just a heads up for the career . There are plenty of stuff out there to learn . My first rubik solve took 8 minutes . And gradually learning the algos took me down to 40 seconds . Hence , practice the beginner method well and understand the pieces, movements, orientations, layers and turns .

Step 4 : Algos – Most important part

Usally, people start learning algos in the way we do CFOP – Learning the Cross , then F2L Algorithms , then OLL algorithms and at last PLL algorithms . Even i learn the same way . But , i think following method works really well (Yes, i have tried by teaching my friends )

1. There are 21 PLL algorithms. Learning 1 a day you can avoid last 2 forumulas to complete the last layer of the cube.

2. Cross in the bottom . Practice solving cross in the bottom layer with good tricks . Make use of the inspection time and track the pieces quickly to solve cube in seconds .

3. Intuitive F2L. Trust Me. instead of putting lot of efforts in learning 40 odd F2L formulas , just try spending time on intuitive F2L. Once you understand and practise it for some time , F2L solve is damn easy .

4. OLLs – oh god . 60 odd formulas . Cut it down into groups . First learn essestial 8 algos (all edges oriented correctly ) which will cut you few RUR’UR2R’. Then try to know how you can avoid Dotted OLLs , by intelligently inserting the last F2L pair. And the rest, learning 1 a day .

Step 5 : Finger Tricks – The magic

Each layer turn just needs a flick with an appropriate finger . Learn how you can utilize the finger tricks and practise it .

Step 6 : Solve , Solve , Solve

Keep practicing the algorithms . One day you will be holding the title of “FASTEST RUBIK CUBE SOLVER IN THE WORLD”