## Posts

Showing posts from September, 2017

### Hackerrank: Sherlock and Squares

Solution to that problem in C++ is as following.

### Heckerrank Problem: Birthday Cake Candles

This is a solution to Hackerrank's algorithm problem

Implementation of the same problem in C++ is as following.
#include #include #include #include #include using namespace std; int main() { int age_n; std::vector candles_n; int input; cin>>age_n; while(cin >> input) candles_n.push_back(input); int largest_height = *std::max_element(candles_n.begin(), candles_n.end()); int mycount = std::count (candles_n.begin(), candles_n.end(), largest_height); cout << mycount; return 0; }

### Counting Inversion: Piggybacking on Merge Sort with Python and C++

This is a solution to Coursera's algorithm problem

import os def main(): array = [] with open("IntegerArray.txt") as file: array = [line.strip() for line in file] mergesort(array) def merge(a,b): c = [] count = 0 while len(a) != 0 and len(b) != 0: if a < b: c.append(a) a.remove(a) count += 1 else: c.append(b) b.remove(b) count += 1 if len(a) == 0: c += b else: c += a # print("\n\n\n\n"+str(count)+"\n\n\n\n") return count def mergesort(x): if len(x) == 0 or len(x) == 1: return x else: middle = len(x)/2 middle = int(middle) a = mergesort(x[:middle]) b = mergesort(x[middle:]) return merge(a,b) if __name__ == '__main__': main() Implementation of the same problem in C++ is as following.
#include "bits/stdc++.h&qu…