Category Archives: Algorithm

Tower of Hanoi Recursion




Formula: 2^n-1


Recursion in C


Another code:
it’s not tail recursion

//printing from stack


Extract Digits From a Number and Make a Sum of all the digits and show this in C

Code is here:


Modular Beautiful Code: 😀

Actually array return function is not directly possible in C and I am finding the solution here.

Took Slightly Help From this link:

How to improve Algorithmic Thinking ?

Check The Number Is Prime Or Not in C, Easy and Details Explanation

Simple Logic For Finding Prime Number is primarility test is 2 to root of n..Source: Wikipedia

The property of being prime is called primality. A simple but slow method of verifying the primality of a given number n is known as trial division. It consists of testing whether n is a multiple of any integer between 2 and {\displaystyle {\sqrt {n}}}{\sqrt {n}}. Algorithms much more efficient than trial division have been devised to test the primality of large numbers. These include the Miller–Rabin primality test, which is fast but has a small probability of error, and the AKS primality test, which always produces the correct answer in polynomial time but is too slow to be practical. Particularly fast methods are available for numbers of special forms, such as Mersenne numbers. As of January 2016, the largest known prime number has 22,338,618 decimal digits.


simple code:


Another Code That Can Also show up the sum of the primes.

Playing With The Logic: Slightly Changed in Return Value 😉 😀

Made the code more dynamic and taking input from users: 😀

Vid explained:


Don’t be developer without coding knowledge in DS and Algo

Dear friends,

I have close to 9 years of experience in the IT industry. I have been working in Java/J2ee background throughout my experience.

I have never worked or know in detail about datastructures & algorithms throughout my career. Hence I found it very difficult to get a high paying job.

I started preparing by solving n number of problems in datastructures & algorithms available in HackerRank (HackerRank), HackerEarth, Techdive (Java Interview Questions & Answers). It was very helpful and I gained more confidence to crack the interview.

Finally I landed up in a high paying job in a product development company.

My advice is, if you are not strong in DS & Algorithms it is very difficult to get a high paying job (above 20 lacs) in a product development company. Remember in a service based company the average salary you can get for 9+ experience is only (14 – 17 lacs in Chennai). The number of high paying product companies & startups are very less in Chennai compared to Bangalore. So you got to be highly competitive to get atleast above 20 lacs.

I will list out some of the top paying companies in Chennai.


Software AG










The things is these companies expect highly skilled professionals but they pay well.

The basic skills which they look for in a software developer is problem solving & Analytical skills, strong in datastructues & Algorithms, OOPS & OS Fundamentals.

You should be very strong in datastructures & algorithms, in-depth understanding of the technologies you work on and you should be a hardcore techie.

Majority of Java developers are good in latest technologies like Spring/Struts hibernate , REST Webservice, Oracle, Jquery, Angular JS, AWS, Hadoop and much more… but the lack of this one skill (DS & Algo) is making them stay far behind in getting a high paid job. Remember if the basement is not strong then there is no use in constructing a 100-storey building.


Many Java developers ask the question, why do we need to learn datastructures & Algorithms as we never use them in day-to-day programming job. As the Java framework is advanced it has all the API’s to manage data and there are also third party api’s available to work with collections. Hence in day to day programming life we never use DS & Algorithms as a java developer as all the API’s are already built-in. Even I had the doubt and even asked the interviewer about it… The reason is pretty simple & straight forward

Can you imagine a software product or programming language without DS & Algorithms?

As a Java developer we may know how to use an arraylist/hashmap/set etc., but how do they really work internally? They are made up of datastructures like linkedlist/binarytree. Java framework contains API’s for sorting hence we use it like a blackbox and never know which algorithm it really uses(merge sort). What if our requirement changes and we need a different sorting algorithm altogether?

As a java developer it may be easy to use the API’s or third party libraries to handle data, but without fundamental knowledge of DS & Algorithms we cannot choose/compare various api’s which suits our requirement.

If you are strong in fundamentals (DS & ALgorithms/problem solving).. you can work with any programming language & solve complex business problems with ease.

Hence top product companies look for these fundamental skills in interviews.

You should be patient and at the same time persistent to achieve your goals. Try to attend as many interviews as possible until you reach your goal. Initial failures or fear of failures should never stop you. I have failed in more than 30 interviews for about 1 year before tasting success.

First of all, set your goals, make a plan and work towards it. Never ever give up for anything until you succeed.

You may wish for anything, there is no limit to what you wish for in your life… but you’ll only get what you deserve. This is an universal fact.

Try to imagine that you have already succeeded at least once or twice a day.

If you set a goal don’t compromise it for anything. Once you start compromising , then it will become your habit and you’ll be average throughout your life.

As a matter of fact, anything is possible in this life but you should make yourself eligible for it.

All the best! Success is yours!


What you learn try to learn from Fundamentals

Whatever you choose just stick with the basic (Data Structure, Database design, Algorithm etc.). Both have good future. I am also in similar situation like you (doing work in both PHP and Android from last 2 years). I found it is very important to have good command over basics.

How to take limited constraint 1<=A[i]<=10^9 Array in C/C++ code for OJs



Hackerearth: Linear Search Algorithm Problem

Default :


Algo: Linear Search


Another Code By Me:

Best Case: O(1)
Worst Case: O(n)
Average Case: O(n/2)=O(n)

Pseudocode Looks Like this:


Another Good Pseudocode:


Interview: Find Occurances in an Array – Binary Search Application

Some theory:


Optimized Code: Using Binary Search



Algorithm: Binary Search

iterative code:

//mathay rakhte hobe function e loop statement e auto return korey while condition er baire gele return korbe -1.. -1 eta return kortese amader nijeder kollane jate index e ei return value niye kaaj korano jay pore

Worst Case: O(logn)

recursive code:

Algo Pseudo Code:



Count number of 2’s in a given range (0 to n)? (ex: range between 0-20, Ans: 3 (i.e [2], 1[2], [2]0))

Google Search:



Programmer/Engineers Quotes

  1. Change is the only constant. Don’t fear it and keep moving forward.
  2. Learn to ignore which/who doesn’t matter to you. Don’t let opinions of random people of “society” influence your decisions who don’t even understand you actually.
  3. Success is a relative term. Do what you are passionate about. Life is not always fair but if you do something out of love and passion, you got nothing to lose.
  4. Face your fear. Take risk. If you never attempt, you will never know what you are missing.
  5. Take control of your own life. If life is a car, you are the one who is driving it. Some people can give you company time to time but its ultimately your journey.



Java For Competitive Programmers


Java certification will worth in this case to learn the language good but problem solving with algorithms must be needed.


Java Certifications: