9.6Givenamatrixinwhicheachrowandeachcolumnissorted,writeamethodtofindanelementinit.voidsearch(int[][]a,intt)
{
intm=a.length;
intn=a[0].length;
//Startfromright-uppoint.
//ifrightUp==t,found
//ifrightUp>t,allcolumnare>t
//ifrightUp<t,allroware<..
分类:
其他好文 时间:
2014-12-14 18:46:19
阅读次数:
149
9.3Givenasortedarrayofnintegersthathasbeenrotatedanunknownnumberoftimes,giveanO(logn)algorithmthatfindsanelementinthearray.Youmayassumethatthearraywasoriginallysortedinincreasingorder.EXAMPLE:Input:find5inarray(1516192025134571014)Output:8(theindexof5inthea..
分类:
其他好文 时间:
2014-12-14 18:45:30
阅读次数:
130
8.7Givenaninfinitenumberofquarters(25cents),dimes(10cents),nickels(5cents)andpennies(1cent),writecodetocalculatethenumberofwaysofrepresentingncents.intways(intsum,intn,intcent)//centismaxCentallowtouse.
{
if(sum==n)
return1;//thiswayisgood.
if(sum>n)
re..
分类:
其他好文 时间:
2014-12-14 18:44:41
阅读次数:
152
20.11Imagineyouhaveasquarematrix,whereeachcellisfilledwitheitherblackorwhite.Designanalgorithmtofindthemaximumsubsquaresuchthatallfourbordersarefilledwithblackpixels.//Abruteforcesolution.
//n*n
//iteratefromnto1.
//Forn,findallpossiblesubsquare
EnumColor..
分类:
其他好文 时间:
2014-12-14 18:43:36
阅读次数:
225
20.8GivenastringsandanarrayofsmallerstringsT,designamethodtosearchsforeachsmallstringinT.KMPBMFancymethod.
分类:
其他好文 时间:
2014-12-12 16:54:50
阅读次数:
123
20.9Numbersarerandomlygeneratedandpassedtoamethod.Writeaprogramtofindandmaintainthemedianvalueasnewvaluesaregenerated.classMedianNum
{
//O(n)
voidinsert(intn)
{
if(size==0)
{
head=newNode(n);
media=head;
}
elseif(n<head.num)
{
NodenewHead=newNode(n);
ne..
分类:
其他好文 时间:
2014-12-12 16:49:31
阅读次数:
151
1. Epic OA 12/7 submitted, Prob get result by 12/22.2. Yelp 1st phone interview. 15 mins recuriter quick programming, Databasequestions.3. FactSet 1.....
分类:
其他好文 时间:
2014-12-12 11:32:18
阅读次数:
142
19.11Designanalgorithmtofindallpairsofintegerswithinanarraywhichsumtoaspecifiedvalue.
//Assumeaisnotnull.
//
//aisnotsorted.
//
//Option1isusingaset.
List<Pair<Integer,Integer>>sumUpTo(int[]a,intsum)
{
//Option1
Map<Integer>set=newHashSet&..
分类:
其他好文 时间:
2014-12-11 10:36:22
阅读次数:
168
20.1Writeafunctionthataddstwonumbers.Youshouldnotuse+oranyarithmeticoperators.//SorryIdon‘tknow.Ihatequestionslikethis.
分类:
其他好文 时间:
2014-12-11 10:35:54
阅读次数:
133
20.2Writeamethodtoshuffleadeckofcards.Itmustbeaperfectshuffle-inotherwords,each52!permutationsofthedeckhastobeequallylikely.Assumethatyouaregivenarandomnumbergeneratorwhichisperfect.//Randomlygenerateaintkfrom1(inclusive)ton(inclusive).
intrandom(intn);
cl..
分类:
其他好文 时间:
2014-12-11 10:35:50
阅读次数:
165