We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am starting a new journey, and doing coding challenges in ZigLang. IAW the rules of this platform, I will not post the solution in the editorial.
conststd=@import("std");constexpectEqualSlices=std.testing.expectEqualSlices;constCompareOrder=struct{fncompare(_:void,lhs:[2]i32,rhs:[2]i32)bool{if(lhs[0]<rhs[0])returntrue;if(lhs[0]>rhs[0])returnfalse;returnlhs[1]<rhs[1];}};pubfnjimOrders(allocator:std.mem.Allocator,orders:[]const[2]i32)![]i32{// Assignconstcount=orders.len;// Allocatevarqueue=tryallocator.alloc([2]i32,count);varresult=tryallocator.alloc(i32,count);// Aftermathdeferallocator.free(queue);returnresult;}test"all orders done at same time"{constallocator=std.testing.allocator;constorders=[_][2]i32{.{1,2},.{2,3},.{3,3}};constoutput=[_]i32{1,2,3};constresult=tryjimOrders(allocator,orders[0..]);deferallocator.free(result);tryexpectEqualSlices(i32,result,output[0..]);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jim and the Orders
You are viewing a single comment's thread. Return to all comments →
I am starting a new journey, and doing coding challenges in ZigLang. IAW the rules of this platform, I will not post the solution in the editorial.