Sort by

recency

|

30 Discussions

|

  • + 2 comments

    O(N*M)

    int twoRobots(int M, int N, vector<vector<int>> queries) {
        vector<vector<int>> cache(N, vector<int>(M+1, INT_MAX));
        set<int> endStates = {0};
        cache[0][0] = abs(queries[0][1] - queries[0][0]);
        for (int i=1; i < N; i++) {
            for (int x : endStates) cache[i][x] = cache[i-1][x] + abs(queries[i][0] - queries[i-1][1]) + abs(queries[i][1] - queries[i][0]);
            int temp = INT_MAX;
            for (int y : endStates) {
                if (y != 0) temp = min(temp, cache[i-1][y] + abs(queries[i][0] - y) + abs(queries[i][1] - queries[i][0]));
                else temp = min(temp, cache[i-1][y] + abs(queries[i][1] - queries[i][0]));
            }
            cache[i][queries[i-1][1]] = min(cache[i][queries[i-1][1]], temp);
            endStates.insert(queries[i-1][1]);
        }
        return *min_element(cache[N-1].begin(), cache[N-1].end());
    }
    
  • + 0 comments

    Hello, I tried an algorithm that worked on my IDE, but its wrong when i submit my solution. I think i didn't quite well understood the input format... here is the input i tried on my IDE :

    inp = [[5,4],[1,5], [3,2], [4,1], [2,4], [4,2], [1,2], [4,3], [10,3],[2,4], [5,4], [9,8]]
    print(two_robots(3,inp))
    

    I got the right output : 11, 2, 5 my algo is :

    def two_robots(m,queries):
        i = 0
    
        def min_dist(queries):
    
            n = len(queries)
            i = 1
            R1, R2 = queries[0], None
            D1, D2 = abs(queries[0][1]-queries[0][0]), 0
    
            while ((R2 is None) and (i< n-1)):
                if abs(queries[i][0] - R1[1]) > abs(queries[i+1][0] - R1[1]):
                    R2 = queries[i]
                    D2+= abs(R2[0] - R2[1])
                else:
                    D1+= abs(R1[1]- queries[i][0]) + abs(queries[i][0] - queries[i][1])
                    R1 = queries[i]
                i = i+1
            if R2 is None:
                R2 = queries[i]
                D2+= abs(R2[0] - R2[1])
            else:
                while (i < n):
                    if abs(queries[i][0]- R1[1]) > abs(queries[i][0] - R2[1]):
                        D2+= abs(R2[1]- queries[i][0]) + abs(queries[i][0] - queries[i][1])
                        R2 = queries[i]
                    else:
                        D1+= abs(R1[1]- queries[i][0]) + abs(queries[i][0] - queries[i][1])
                        R1 = queries[i]
                    i = i+1
            return D1+D2
    
        resultats = ""
        while i < m:
            n_cut = queries[0][1]
            res = min_dist(queries[1:n_cut+1])
            resultats = resultats + str(res) + "\n"
            queries = queries[n_cut+1:]
            i = i+1
        return resultats
    

    I get an error when i run this solution on hackerRank. Can anyone of you plz, give an example of the input and output, that the function, is supposed to get?? Thank you in advance

  • + 1 comment

    It seems like you're referring to "Two Robots," but I'm not sure what specific information or context you're looking for. "Two Robots" could refer to a concept, story , movie, game table, or any number of things. Could you please provide more details or clarify your request so I can assist you accurately?

  • + 0 comments

    Here is my solution in java, javascript, python, C ,C++, Csharp HackerRank Two Robots Problem Solution

  • + 1 comment

    When I was just thinking of robotic process automation, I was sure that I'd have to deal with such problems and their salvations myself. But now I know that companies like Deusrobotics.com provide software that's easy-to-use for any workers, and I think it's actually helpful because it allows focusing on more important aspects of business development.