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.
public static List<int> IcecreamParlor(int m, int[] arr)
{
var pairs = arr.Select((x, i) => (x, i)).OrderBy(p => p.x).ToArray();
arr = pairs.Select(p => p.x).ToArray();
var idxs = pairs.Select(p => p.i+1).ToArray();
var i=0;
var j=arr.Length-1;
while(true){
var v = arr[i] + arr[j];
if(v == m) return new List<int>{idxs[i], idxs[j]}.Order().ToList();
if(v > m) j--;
if(v < m) i++;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →