ambu.sreedharan
BAN USERRemote newRemote = new Remote();
Button newButton = new Button(color, name);
Battery newBattery = new Battery(someVolt);
//changes the battery
newRemote.updateBatteries(newBattery);
//add a button to its internal hashmap that has name associated with buttons.
newRemote.addButton(newButton);
//to press a button on remote you can say
newRemote.getButton("power").execute();
So the above end code will tell you that you need a Button class, a Battery class.
To take it further. The Button class can have a execute() function. Battery could have getRemainingPower() function.
why oh why recursion
- ambu.sreedharan October 30, 2013bool palindrome(string str){
for(int i = 0, j=str.length() -1; i<str.length()/2; i++, j--){
if(str[i] == ' ') i++;
if(str[j] == ' ') j--;
if(str[i] != str[j]){
cout<<str[i]<<" "<<str[j];
return false;}
}
return true;
}
- ambu.sreedharan October 30, 2013very neat
- ambu.sreedharan September 25, 2013So what you need is a method than can convert a inorder traversed string back to a tree?
- ambu.sreedharan September 10, 2013We can assume N to be lesser than M and hence if we could open all files and read the first number, you can see which is the largest and thus write that to a new file and increment the file pointer in the file we just took the number off of. This is the merge out of the merge sort.
- ambu.sreedharan August 06, 2013#include<iostream>
using namespace std;
int equilibrium(int * arr, int size){
int sum = 0;
int left_sum = 0;
for (int i = 0; i<size; i++){
sum+=arr[i];
}
for(int i = 0; i<size; i++){
sum -= arr[i];
if(sum == left_sum) return i;
else left_sum+=arr[i];
}
return -1;
}
int main(){
int arr[] = {3,-3,8,6,-1,-5};
int size = 6;
int equil = equilibrium(arr, size);
cout<<equil;
}
#include<map>
#include<iostream>
using namespace std;
int main(){
int arr[] = {6,7,7,8,8,2,3,8,8,11,23,8,8,7,3,3,4,4,4};
int size = 18;
map<int, int> mymap;
for(int i = 0; i<size; i++){
if(mymap.count(arr[i])>0) mymap[arr[i]]++;
else mymap[arr[i]] = 1;
}
int largest = 0;
for(map<int, int>::iterator it = mymap.begin(); it!=mymap.end(); ++it){
if((*it).second > mymap[largest]) largest = (*it).first;
}
cout<<largest;
}
How about having a basic interface
car {
make
model
year
engine
tires //array of tire objects
move_forward()
move_backward()
turn_left()
turn_right()
}
2_door_car implements car {
left door
right door
}
4_door_car implements car{
left door
right door
back left door
back right door
}
And so on for 2 seater or 4 seater. We can have engine as an interface too that have many different types of engine implementation.
got it. Sounds like there are M number of individuals who follow. And each of them can follow more than one. We need K number of individual followers.
- ambu.sreedharan July 18, 2013How is it 0th and 2nd. That adds up to 6. 0th and 1st adds up to 5. Am I understanding the question wrong?
- ambu.sreedharan July 18, 2013
Reptaylorjose221, Production Engineer at BT
Graphic designer with a strong background in marketing design.Having a day off during the week to do whatever I ...
Recursive approach
- ambu.sreedharan January 18, 2014