You are viewing a single comment's thread. Return to all comments →
A brute force solution, good to compare against a routine:
// Complete the solve function below. static int[] solve(int[] h, int difference, int[][] queries) { List<int> ret = new List<int>(); for(int query=0; query < queries.Length; query++) { int inicio = queries[query][0]; int fim = queries[query][1]; int total = 0; for(int iextertno = inicio; iextertno < fim; iextertno++) { for(int iinterno = iextertno+1; iinterno <= fim; iinterno++) { int diff = Math.Abs(h[iextertno] - h[iinterno]); if(diff <= difference) total++; } } ret.Add(total); } return ret.ToArray(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Almost Equal - Advanced
You are viewing a single comment's thread. Return to all comments →
A brute force solution, good to compare against a routine: