Problem Statement
Create a class ShortPath with a method steps that is given
Definition
- Class:
- ShortPath
- Method:
- steps
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int steps(int[] x, int[] y)
- (be sure your method is public)
Constraints
- x will have between 2 and 50 elements inclusive.
- y will have the same number of elements as x.
- Each element of x will be between -1,000,000,000 and 1,000,000,000 inclusive.
- Each element of y will be between -1,000,000,000 and 1,000,000,000 inclusive.
- The start and finish points will be distinct from each other and from all other points given by x and y.
Examples
{0,2,1}
{0,2,1}
Returns: 3
3 --|--|--|--|--|--|-- 2 --|--|--F--|--|--|-- 1 --|--X--|--|--|--|-- 0 --S--|--|--|--|--|-- 0 1 2 3 4 5 In the diagram, S is the start point, F is the finish, and X is forbidden. There are two different paths of length 3, one of which is S to (0,1) to (1,2) to F. The direct path of length 2 is blocked by the forbidden point.
{0,1,2,2}
{0,1,2,2}
Returns: 1
Take a single diagonal step from (0,0) to (1,1). The second appearance of (2,2) on the forbidden list is legal but never matters.
{1,100000,0,0,0,2,2,2,1,1}
{1,200000,0,1,2,0,1,2,0,2}
Returns: -1
The start point is trapped in a square of forbidden points.
{1,100000,0,0,0,2,2,2,1}
{1,200000,0,1,2,0,1,2,0}
Returns: 199999
{-1000000000,1000000000,-1,0,1,2}
{-1000000000,1000000000,0,0,0,0}
Returns: 2000000002
{-100000,100000,0}
{100000,-100000,0}
Returns: 200001
{0,1000000000,1,1,0,-1,-1,-1,-1,0,1,2,3,3,3,3,3,3,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-3,-2,-1,0 ,1,2,3,4,5,5,5,5,5,5,5,5,5,5,4,3}
{0,1000000000,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,0,1,2,3,4,4,4,4,4 ,4,4,4,4,3,2,1,0,-1,-2,-3,-4,-5,-5,-5}
Returns: 1000000032
{-1000000000,1000000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
{-1000000000,1000000000, -24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}
Returns: 2000000024
{-1000000000,1000000000,-36567890,-592272557,360999009,-256765686,956334048,-955009547,210138297,508675457,291827863,393885093,611106914,-111404223,961611797,-609924897,72614068,-829121416,-651071498,-422993788,-726282586,-829940505,660058865,397260893,-533687536,756400205,-377165247,-214372814,643787593,-983298453,71257425,519440799,-509064102,416806751,-83944748,-211848418,-889895756,-304751643,-188544587,224457138,-855688085,-436845057,656252758,281921184,-872810330,-673882647,-357846174,-191102491,-317859625,766987116}
{-1000000000,1000000000,729799412,73827713,571874326,412865925,-258751468,852689729,311727809,-318474390,73812424,-335883740,109979498,282130045,-957418748,288818550,680922749,-772131909,-597553346,923197147,757467650,-495975019,-680835091,38553617,389893600,641892287,743069861,-122134675,-967728246,388559697,173931820,-138682587,-621045909,-678583171,4425222,349991742,-683995134,-14431424,-406675448,-466165981,194709316,855726309,427899879,437099100,268624202,925140388,-26727314,-978802998,577094587,-397344876}
Returns: 2000000000
{-3,5,-4,-2,-7,5,-6,-1,-3,-5,-6,-4,-1,5,-7,-8,-7,9,-8,-9,-8,6,6,-4,2,-8,1,1,-7,4,7,1,5,9,3,-9,10,-6,8,-10,-2,-10,-2,-1,-4,-5,7,-2,-4,-1}
{9,0,0,0,5,8,-1,5,1,4,1,3,-3,7,10,6,7,-7,10,-7,-7,8,-10,-1,4,-6,5,-9,-8,-4,-6,4,1,6,1,7,9,2,2,-7,-5,-2,-6,8,-2,2,-7,-6,3,-2}
Returns: 10
{-8,-2,2,-8,6,9,-3,10,-1,-7,-1,9,5,-4,-6,-8,-1,-6,-1,-6,7,-4,-6,-7,2,3,-7,2,-6,5,8,-4,7,4,-7,5,-6,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,-999999900,-999999900 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900 ,-999999924,-999999901,-999999902,-999999903,-999999904,-999999905 ,-999999906,-999999907,-999999908,-999999909,-999999910,-999999911 ,-999999912,-999999913,-999999914,-999999915,-999999916,-999999917 ,-999999918,-999999919,-999999920,-999999921,-999999922,-999999923}
{-999999901,1000000000 ,-999999900,-999999901,-999999902,-999999903,-999999904,-999999905 ,-999999906,-999999907,-999999908,-999999909,-999999910,-999999911 ,-999999912,-999999913,-999999914,-999999915,-999999916,-999999917 ,-999999918,-999999919,-999999920,-999999921,-999999922,-999999923 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900 ,-999999900,-999999900,-999999900,-999999900,-999999900,-999999900}
Returns: 1999999947
{-999999990,1000000000,-999999989,-999999989,-999999990,-999999991,-999999991,-999999991,-999999991,-999999990,-999999989,-999999988,-999999987,-999999987,-999999987,-999999987,-999999987,-999999987,-999999988,-999999989,-999999990,-999999991,-999999992,-999999993,-999999993,-999999993,-999999993,-999999993,-999999993,-999999993,-999999993,-999999992,-999999991,-999999990,-999999989,-999999988,-999999987,-999999986,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999986,-999999987}
{-999999990,1000000000,-999999990,-999999991,-999999991,-999999991,-999999990,-999999989,-999999988,-999999988,-999999988,-999999988,-999999988,-999999989,-999999990,-999999991,-999999992,-999999993,-999999993,-999999993,-999999993,-999999993,-999999993,-999999993,-999999992,-999999991,-999999990,-999999989,-999999988,-999999987,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999987,-999999988,-999999989,-999999990,-999999991,-999999992,-999999993,-999999994,-999999995,-999999995,-999999995}
Returns: 2000000022
{-999999990,1000000000,-999999989,-999999989,-999999990,-999999991,-999999992,-999999992,-999999992,-999999992,-999999992,-999999992,-999999991,-999999990,-999999989,-999999988,-999999987,-999999986,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999985,-999999986,-999999987,-999999988,-999999989,-999999990,-999999991,-999999992,-999999993,-999999994,-999999995,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996,-999999996}
{-999999990,1000000000,-999999990,-999999991,-999999991,-999999991,-999999991,-999999990,-999999989,-999999988,-999999987,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999986,-999999987,-999999988,-999999989,-999999990,-999999991,-999999992,-999999993,-999999994,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999995,-999999994,-999999993,-999999992,-999999991,-999999990,-999999989,-999999988,-999999987,-999999986,-999999985,-999999984}
Returns: 2000000006
{1000000000,-1000000000,-999999999}
{1000000000,-1000000000,-999999999}
Returns: 2000000001
{1000000000,-1000000000,1000000000,1000000000,999999999,999999999,999999999}
{999999999,-1000000000,1000000000,999999998,1000000000,999999999,999999998}
Returns: 2000000002
{2,4,3,4,5,3,3,4,5}
{3,3,2,2,2,3,4,4,4}
Returns: 7
{2,4,3,4,5,3,3,4,5,1,2,1,2}
{3,3,2,2,2,3,4,4,4,2,2,4,4}
Returns: 10
{ 1,6,0,1,2,3,0,1,2,3,2,4,5,6,7,5,5,6,7,5,5,5,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,3,3 }
{ 3,4,2,2,2,2,4,4,4,4,3,3,3,3,3,4,5,5,5,6,7,8,9,10,11,12,13,14,15,1,0,-1,-2,-3,-4,-5,-6,-7,-8 }
Returns: 15
{296332854,-306578732,-155937092,-264705332,988264921,-958586598,-130754389,-466368532,-630020082,213150761,-847383518,-335159145,-163545862,693117289,-248655377,-637984092,71563067,225290421,-212128152,926892248,-355872486,-38037836,999050233,198954238,428847357,-726619581,-949156446,500281519,-126835017,199800913,939264475,-548255373,-968118776,-866225301,291330125,877879739,-882886391,-389604686,99877544,103233498,-56556306,754053983,-490229848,-50297187,-774449098,-154613149,158030487,841592256,-896879437,-947147249}
{-664339905,-819017396,280955743,-272738149,-533024579,792615172,298308698,-990400218,33489015,52941736,-255950036,-312215493,543807610,-984928922,-124185543,-482092368,-855794246,603749645,229274322,334935485,-437622401,-889594598,-472779987,-539820279,807614508,-285613739,785932458,114353851,52768138,381527616,-703636176,-827698387,945015042,209898873,-27230569,-631224304,-930948511,-949037175,-368623215,-104400980,-109083654,194666264,37203846,30289031,-514410355,544176373,526648531,-687706104,-880688244,-591251344}
Returns: 602911586
{-882866464,-933257150,661058581,58600264,-677231648,27294622,951263440,-953339602,-152807895,881872662,-218492201,257457100,-286107996,25729258,764832398,87179954,-990854606,-275268222,893244299,320997477,307456216,877756913,-83438785,309944255,633826703,837521874,-77523542,468697968,782583275,-503557329,-524460203,831132474,214605150,498186918,451161535,-408771325,-293567723,-496474923,-829040997,-256763375,153726828,-803475490,559410491,-64066090,720831448,-405932961,-85119790,685534231,-803483337,61422189}
{946434231,454318033,72842580,-595823163,979705500,-517954946,707347097,-167653746,622550423,424227121,-358169307,-12450701,534020074,-572357458,634564571,449043204,-430035716,-989814049,486452995,-633209310,-525056315,200314865,258008601,207186383,-81985250,-311879405,-533710112,-888486725,28393449,-231121307,200442390,29766487,787038393,-577449795,141063284,700735317,-427730763,380282078,418203656,-989920850,-77413199,357910403,227279697,-863425132,490933576,-377492614,583495332,364402876,-388593212,742996726}
Returns: 492116198
{835144333,83758244,970691400,800925328,562388247,870766038,-301783534,-273176535,-240092304,-510354371,-141437021,285112075,545266923,864036719,-826305364,182083883,-965583790,926488894,-179146524,338102223,-409931765,-26865321,200059486,-726103173,96250961,-977516530,386205257,284756406,849555162,661691042,307456723,480589019,660674875,919121016,478579928,-392881244,710307076,-905732670,60444,84698752,495868548,421670270,-857181004,-441668883,-816700900,84009823,455542846,-337837113,-420234284,-711463850}
{540716365,129978727,331165683,530529889,-141051167,997983624,-24409967,588703491,30399268,257190585,439873575,-919109363,-670605334,-924912391,-685069020,-288816281,-490132233,-359542625,-505824075,694429762,-364497588,912033341,-253340382,52600845,725658934,-770754717,729758688,-814235163,-660466710,522943765,-406577621,926774156,-550264571,-739887427,889816178,-86117702,18181309,752200312,-200591388,363410477,352784783,-20546369,107655348,-63139004,-276914534,729390252,-157172329,936622948,-706658409,-921785794}
Returns: 751386089
{-537409747,-174546950,-823813395,742878814,548453004,-399899669,-892734741,-931676846,775957567,260435711,-228222443,961656173,269288306,-932369199,-357321988,-846382753,427735907,750324618,20251695,-419380422,336102121,203758391,407067198,848352607,-108035636,235565186,45408396,-76209698,255747037,-64115662,917847337,-377532799,-961933258,655496423,-457490219,-668286778,-877328471,-266518111,-201459329,182284319,7830803,142436753,-958827183,-490357866,-489113649,791713149,-818635980,873362857,264001,-20346518}
{738822141,592776983,-566960807,44048132,494996377,-169816948,-871077009,-851861145,15312923,-461687495,-540347732,-297771916,376512226,-421801485,511621135,-715696140,-93825902,-842294287,-731210347,97153006,-745822061,877278222,-469174213,-812841150,231827821,287641884,468299361,532305602,-73262617,-691294979,586063048,493582705,505280332,540441611,-224660980,-845281156,452720084,601629268,-748334870,-371544052,-219531325,496891927,-446954251,-557985082,-251596807,-600650060,794822566,-834007536,583647910,-152607530}
Returns: 362862797