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.
My Java solution with o(n) time complexity and o(1) space complexity:
publicstaticList<Integer>compareTriplets(List<Integer>a,List<Integer>b){intaliceScore=0,bobScore=0;//iterate over each valfor(inti=0;i<a.size();i++){intalicePts=a.get(i);intbobPts=b.get(i);//if a[i] > b[i], increase alice pointsif(alicePts>bobPts)aliceScore++;//if a[i] < b[i], increase bob pointselseif(alicePts<bobPts)bobScore++;}//return list of alice and bobs pointsreturnArrays.asList(aliceScore,bobScore);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Compare the Triplets
You are viewing a single comment's thread. Return to all comments →
My Java solution with o(n) time complexity and o(1) space complexity: