Spot Capacity Round Trips tests accept the two largest rising runs

Abierto Apto para principiantes
#691 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@peter1001136 ya está trabajando en esto.

Desde el 13/11/2026.

  • #692 de @peter1001136 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp, json
Área
testing, tooling

Línea de trabajo

Empieza con problem-bank/judges.json y busca los casos de Spot Capacity Round Trips. Añade la entrada reportada [[1,2,4,2,5,7,2,4,9,0]] con el valor esperado 13 y, después, vuelve a generar los jueces según lo solicitado. La tarea estará terminada cuando el caso añadido rechace la solución incorrecta descrita, mientras que una solución correcta siga pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Observed behavior

In Spot Capacity Round Trips (best-time-to-buy-and-sell-stock-iii, LeetCode 123), the built-in tests accept a solution that splits the prices into rising runs and adds the two largest run gains. It passes 6/6, the same as a correct solution.

class Solution {
public:
    int bestTwoRoundTrips(vector<int>& prices) {
        vector<int> gains;
        int n = prices.size(), i = 0;
        while (i < n - 1) {
            int j = i;
            while (j + 1 < n && prices[j + 1] >= prices[j]) j++;
            if (prices[j] > prices[i]) gains.push_back(prices[j] - prices[i]);
            i = j > i ? j + 1 : i + 1;
        }
        sort(gains.rbegin(), gains.rend());
        int total = 0;
        for (int k = 0; k < (int)gains.size() && k < 2; k++) total += gains[k];
        return total;
    }
};

It never joins two runs into one trade across a dip. On [1,2,4,2,5,7,2,4,9,0] the runs gain 3, 5 and 7, so it returns 12. The answer is 13: buy at 1 and sell at 7, then buy at 2 and sell at 9. Every built-in case has at most two rising runs, or its best pair of trades is already two whole runs, so the tests cannot tell the two apart. The same solution written in Python also passes all 6 and returns 12 on the case above, since every language runs the same judge cases.

Expected behavior

At least one built-in case has three or more rising runs where the best two trades span a dip, so this solution fails the tests. A correct solution still passes every case.

Reproduction
  1. Run CodeTrial at the revision below and open Spot Capacity Round Trips with C++.
  2. Paste the solution above and run the tests. All 6 built-in cases pass.
  3. Under "Add a case", enter [[1,2,4,2,5,7,2,4,9,0]] as the input and 13 as the expected value, then run again. The new case fails with got 12.
CodeTrial version

codetrial 0.1.0 (c54aed7), built from source. The judge for this problem is unchanged between c54aed7 and main at d0544857.

Environment
  • OS: Windows 11 with the server in WSL2
  • Browser: Chrome 157.0.8103.51
  • Language: C++
  • Interview loop: Coding
  • Problem: Spot Capacity Round Trips (LeetCode 123)
  • REACTO or STAR step: Test
  • Reconnect: None
Sanitized evidence

All 6 built-in cases pass, and the added case fails with got 12:

image
Public data confirmation
  • I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.

I would like to fix this by adding that case to problem-bank/judges.json and regenerating the judges. Please assign it to me.

Lenguaje dominante
Rust
Estrellas
228
Forks
150
Merge medio
1 d 3 h
PR fusionados (30 d)
226

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sysprog21/codetrial

Todos los issues de sysprog21/codetrial

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.