Category Archives: ACM

Hackerearth: COUNT NUMBERS



Hackerearth: Fredo and Game




Hackerearth: Little Jhool and psychic powers


another solution of mine:



Hackerearth: Complete the Syllabus

Copied the code from someone’s solutions:

code from editorial:


Heap Sort

If we want to sort in ascending then we create a min heap
If we want to create in descending then we create in max heap

Once the heap is created we delete the root node from heap and put the last node in the root position and repeat the steps till we have covered all the elements.
For ascending order:
1. Build Heap
2. Transform the heap into min heap
3. Delete the root node



Implemented code:


Took help from these two links:

Complexity Analysis:
Time Complexity for MaxHeapify: O(logn)
Complexity for BuildHeap: O(n)
Complexity of heapSort:
Worst, Avergae, Base case: O(n*logn)
It is inplace algorithm.
Space Complexity: O(1)

Big Oh, Theta and Omega Notation confusion clearing

Merge Sort

Algorithm Video:

Merge Sort Combines Two Sorted file in a large bigger sorted files:
This Merge sort happens in a two steps:

This sorting is a example of divide and conquer approach:
1. Selection: Splits a list into two lists (This process is recursive approach)
2. Merging: It joins two list in a one list (It follows the pesudocode in itertive manner)



code with extra malloc declaration:

code by me without  extra malloc:


Analysis of Running Time Complexity:

Worst case, Best case, Avergae case: Theta(nlogn)
Space Complexity: Theta(n)


This link can help to solve problems:

Bubble Sort

This video is good to help:

I have also taken help from DS Made Easy by Karumanchi book to find the algo pesudocode.



I need to improve this algorithm as it is not passing all the sizes of array so there will be some vacant position in array which increases the complexity in the running time so we need to out of the loop when it has nothing to swap, so our improvised algorithm will be:




This below video can help for better optimization that implemented in the above code:

Time Complexity in Running Time:

Worst Case: O(n^2)
BEst Case without improve: O(n^2)
Best Case(Improvised): O(n)
Average Case: O(n^2)
Space Complexity: O(1)
Simulation Tried to be drawn by me:


Selection Sort


Implemented Code:




Youtube Video:

Analaysis though it seems little bit tough to me:

HackerRank video:

MIT video:

Pseudo Code from upper Youtube vid:



Slightly edited in *A to A[]:

Some change with before and after show:

Complete Quicksort Implementation and taking user input:

Output from the above code:

Geeks for geeks:

From geeks for geeks but may be there might be some problems there

Another good one for understanding(I think it’s the best one):

Pseudocode available in the above video:

implemented code:



Quick Sorting in Process

Time and Space complexity: Best Case : omega(nlogn)
Worst case: O(n^2)

See this video to clear up the skills:

ideone example:
Others Code:

Google Search Terms:*

Hackerearth – Jarvis and Numbers

code i have understand for last 6 hours:
problem statement was little bit clumsy but understood atlast:

accepted code took help from editorial:

official editorial:


Codeforces: A. Next Round

My code: didn’t passed all testcase:

Then looked out the solution but din’t understand one thing but implemented my own:

Print Hackerearth

I am implementing the solution after seeing the code:


Hackerearth : Digit Problem



10579 Fibonacci Numbers