LeetCode-Feedback / LeetCode-Feedback

643 stars 297 forks source link

[BUG] - Leetcode #0399 for Dart #21936

Open ManuH68 opened 1 month ago

ManuH68 commented 1 month ago

LeetCode Username

Dartist

Problem Number, Title, and Link

0399 Evaluate Division https://leetcode.com/problems/evaluate-division/description/

Bug Category

Incorrect test case (Output of test case is incorrect as per the problem statement)

Bug Description

I got this message at the test case 18/28:

Line 93: type 'int' is not a subtype of type 'double'

0 new List.from (dart:core-patch/array_patch.dart:29:5)

1 deserializeToList (package:serializers/src/deserializers.dart:50:10)

2 main (file:///solution.dart:93:22)

What's happening here I think is that the input for values is [2.0, 3.0, 2]

During the deserialization Dart sees the last number as an int which cause the datatype mismatch in the error message above.

Because of this, nobody will be able to enter a valid Dart solution.

Language Used for Code

Dart

Code used for Submit/Run operation

import 'dart:collection';

class Solution {
  List<double> calcEquation(List<List<String>> equations, List<double> values,
      List<List<String>> queries) {
    Map<String, Map<String, double>> graph = buildGraph(equations, values);
    List<double> results = [];

    for (var query in queries) {
      var [dividend, divisor] = query;

      if (graph.containsKey(dividend) && graph.containsKey(divisor)) {
        var result = bfs(dividend, divisor, graph);
        results.add(result);
      } else {
        results.add(-1.0);
      }
    }
    return results;
  }

  Map<String, Map<String, double>> buildGraph(
      List<List<String>> equations, List<double> values) {
    Map<String, Map<String, double>> graph = {};

    for (var (i, equation) in equations.indexed) {
      var [dividend, divisor] = equation;
      var value = values[i];

      if (!graph.containsKey(dividend)) {
        graph[dividend] = {};
      }
      graph[dividend]![divisor] = value;

      if (!graph.containsKey(divisor)) {
        graph[divisor] = {};
      }
      graph[divisor]![dividend] = 1.0 / value;
    }

    return graph;
  }

  double bfs(String start, String end, Map<String, Map<String, double>> graph) {
    Queue<(String, double)> queue = Queue();
    Set<String> visited = {};

    queue.add((start, 1.0));
    visited.add(start);

    while (queue.isNotEmpty) {
      var (currentNode, currentValue) = queue.removeFirst();

      if (currentNode == end) {
        return currentValue;
      }

      for (var neighbor in graph[currentNode]!.entries) {
        var neighborNode = neighbor.key;
        var neighborWeight = neighbor.value;

        if (!visited.contains(neighborNode)) {
          visited.add(neighborNode);
          queue.add((neighborNode, currentValue * neighborWeight));
        }
      }
    }
    return -1.0;
  }
}

Expected behavior

No error from the input test cases. Numbers should all be stored with a decimal point so that the deserialization process will indentify the numbers as type "double" and not "int".

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 1 month ago

Joyce_Ndisya commented: Hello,

Your reported issue has been relayed to our team for thorough investigation. We appreciate your patience as we work to address and resolve this matter. We will reach out to you when we have updates regarding the issue.

If you have any further questions or concerns in the meantime, please feel free to let us know.

Best regards, LeetCode Support Team

ManuH68 commented 1 month ago

Just to make it clear, the error is coming from the Leetcode test data for Dart. It's a bug in Leetcode. Because of this no Dart submission will ever be accepted while this bug is not corrected. I had to submit my code in an other language to be accepted.

ManuH68 commented 1 month ago

That should not be closed until fixed.

exalate-issue-sync[bot] commented 1 month ago

Joyce_Ndisya commented: Hello there,

Thank you for reaching out.

Checking now, LeetCode has already added this test case at this time.

Your continued feedback is greatly appreciated as we work towards improving our platform.

Best regards, Joyce

ManuH68 commented 1 month ago

Hi Joyce, I just tested it, the error is still there.

exalate-issue-sync[bot] commented 1 month ago

Joyce_Ndisya commented: Hello there.

Apologies for the earlier response.

The relevant team is analyzing the feedback and we will get back to you as soon as possible. We appreciate your patience during this time.

Warm regards, Joyce