Sort by

recency

|

22 Discussions

|

  • + 0 comments

    for complete solution in java c++ and c programming search for programs.programmingoneonone.com on google

  • + 1 comment

    C++ doesn't include k in the solve function definition... Given code is incomplete.

  • + 0 comments

    Can anybody please explain solution?

  • + 0 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();
    }
    
  • + 0 comments

    I'm solving it in Java and I can see the solve method does not have the difference K value to calculate. So I'm changing the method definition, is it acceptable ?