Posts

Showing posts from March, 2019

HACKERRANK EQUAL STACK

HACKERRANK-EQUAL STACK The following function is used to solve the problem  https://www.hackerrank.com/challenges/equal-stacks/problem #include <bits/stdc++.h> #include <string> #include <iostream> #include <vector> using namespace std ; static int t1 = 0 ; static int t2 = 0 ; static int t3 = 0 ; vector < string > split_string ( string ); /* * Author: Y Nguyen * equalStacks function with recursive method * * Space Complexity O(1) */ int equalStacks ( vector < int > & h1 , vector < int > & h2 , vector < int > & h3 ) { /* * Write your code here. */ if ( t1 == t2 && t1 == t3 ) return t1 ; // find the highest town else { if ( t1 >= t2 && t1 >= t3 ) { // remove the first cylinder of the higest stack t1 = t1 - h1 . back (); h1 . pop_back (); } else if ( t2 >= t1 &&