Jack
BAN USER
- 2of 2 votes
AnswersI was asked to explain memento pattern.I explained with this example.
class Originator:ICloneable { public string a; public int b; public object Clone() { Originator o = new Originator(); o.a = this.a; o.b = this.b; return o; } } class CareTaker { List<Originator> l = new List<Originator>(); public void SaveMemento(Originator o) { l.Add((Originator)o.Clone()); } public Originator RetrieveMemento(int i) { return l[i]; } } class Program { static void Main(string[] args) { CareTaker c = new CareTaker(); Originator o = new Originator(); c.SaveMemento(o); } }
The interviewer said this is is different from memto pattern ... can anyone explain where the difference is!!!
- Jack in India| Report Duplicate | Flag | PURGE
Bank of America Software Engineer / Developer Algorithm
A simple approach would be to use a separate table which will be queried by the external system .. If you have a Table A which is to be used by an external system, make a table B which is exact replica of Table A .. Now every 5-10 secs or 1-2 minutes depending upon your requirements, sync the two table by running sql server scheduled job ... So the external system will query table B and get almost realtime data, and this table B is only used by external system..
- Jack October 07, 2013Actually I remember a similar question, where you are provided a Dictionary and a function provided to you to find if the string is a complete word..
Now the problem is purely how you decide on the algo to find words, as O(n) is definitely not an option, each call to the Dictionary is assumed to be very expensive ...
public void PrintSpiral(int[,] a)
{
int minx=0,maxx=a.GetLength(0)-1,miny=0,maxy=a.GetLength(1)-1;
bool directionx=true;
bool directiony=true;
while(maxx!=minx && maxy!=miny)
{
if(directionx==true && directiony==true)
{
int x1=minx;int x2=maxx;
int y=miny;
for(int i=x1;i<=x2;i++)
{
console.write(a[i,y]);
}
directiony=true;
directionx=false;
miny++;
}
if(directionx==false && directiony==true)
{
int x=maxx;
int y1=miny;int y2=maxy;
for(int i=y1;i<=y2;i++)
{
console.write(a[x,i]);
}
directiony=false;
directionx=true;
maxx--;
}
if(directionx==true && directiony==false)
{
int x1=maxx;int x2=minx;
int y=maxy;
for(int i=x1;i>=x2;i--)
{
console.write(a[i,y]);
}
directiony=false;
directionx=false;
maxy--;
}
if(directionx==false && directiony==false)
{
int x=minx;
int y1=maxy;int y2=miny;
for(int i=y1;i>=y2;i--)
{
console.write(a[x,i]);
}
directiony=true;
directionx=true;
minx--;
}
if(maxx==minx && maxy==miny)console.write(a[maxx,maxy]);
}
}
maintain a hastable where key is a number from the array and value its repeatation
Go through the array and keep inserting in dictionary :
if (element is already a key) then increase its count
else add element with count=1
Then go thourgh this dictionary and find if any count is > n/2
class Account
{
object _lock;
double balance;
//constructor
public Account(int Id)
{
_lock=Locker.GetLock(Id);
}
//Make this method synchronized
public Deduct(double amount)
{
lock(_lock){//deduct here}
}
//Make this method synchronized
public Add(double amount)
{
lock(_lock){//Add here}
}
}
static class Locker
{
static Dictionary<int,object> locks=new Dictionary<int,object>();
public static object GetLock(int Id)
{
if(locks.ContainsKey(id)) return locks[id];
else
{
Dictionary.Add(Id,(object)Id); return locks[id];
}
}
}
Repmarilynarhea, Computer Scientist at ABC TECH SUPPORT
I live my life very happily by god grace and I am working as a Gaming machine servicer and my ...
Repmarktrejjo, Data Engineer at Accolite software
I’m Mark.I believe life is too short to be serious all the time, so if you cannot laugh ...
Repjohndbutler0, Aghori Mahakal Tantrik at BMO Harris Bank
I consider myself to be driven, proactive, hard working, a team player, creative and absolutely passionate person! I am strong ...
Repjonesreina93, Hawaiian airlines reservations at American Airlines
Hello, I am currently working at the airport as an air hostess, and my responsibility are Check tickets and assisted ...
Repjimmybdepuy, Front-end Software Engineer at Arista Networks
Hi, I am Jimmy from los Angeles. I am a painter. I have Knowledge of different types and shades of ...
Repdorarwoods, Kuwait airways reservations at Aspire Systems
I am an Application engineer in the network chef company. In my free time, I enjoy reading programming and technology ...
Repcharlespladd, Android Engineer at Abs india pvt. ltd.
I am Charles from Pascoag USA. I have strong knowledge of pain management systems. And I have experience in providing ...
RepCarlERhodes, Cloud Support Associate at Baidu
I am an Engineering manager in Mosier USA. I am a freelance events coordinator and a lifetime entrepreneur. I want ...
should be upto n/2 not square root of n ...
- Jack October 09, 2013Say n=16, then square root will give 4 .. so output will be 1,2; 1,3;2,3 in your algo ..
However output needed should also have 1,5;2,5;3,5;1,7;2,7;