binary-search/Solution.java: prints -1 when the target is the last element (`9 1 3 5 7 9`) or in a 1-element list (`5 5`)
Les mainteneurs répondent en général sous 1 jour
@tanujb03 y travaille déjà.
Depuis le 10/10/2026.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 22/100
Piste de recherche
The bug is in problems/binary-search/Solution.java, where the search reports -1 once it narrows to a single position. Check linked pull request #30 first, since work is already under way. Done means 9 1 3 5 7 9 prints 4, 5 5 prints 0, and 3 1 3 prints 1, with those cases added to cases.txt and python3 run.py binary-search passing.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
What I did
- Fresh checkout of
main, JDK 17. - Compile the Java solution and run it on a few inputs (the input is one line: the target, then the sorted list):
cd problems/binary-search
javac Solution.java
echo "9 1 3 5 7 9" | java Solution
echo "5 5" | java Solution
echo "3 1 3" | java Solution
echo "3 1 3 5" | java Solution
- For comparison, the Python solution:
echo "9 1 3 5 7 9" | python3 solution.py
What I expected
The problem README says: "Print the position (starting from 0) of the target in the list, or -1 if it isn't there." (problems/binary-search/README.md)
So 9 1 3 5 7 9 should print 4, 5 5 should print 0, 3 1 3 should print 1, and 3 1 3 5 should print 1.
What happened instead
9 1 3 5 7 9 -> -1 (expected 4)
5 5 -> -1 (expected 0)
3 1 3 -> -1 (expected 1)
3 1 3 5 -> 1 (correct)
The target is found, then reported as missing, whenever the search narrows to a single position. The Python and C++ solutions print the right answer for all of these. python3 run.py binary-search passes today because none of the cases in cases.txt ends the search on a single remaining position.
Environment
code-corner main @ 0c95800, JDK 17, Windows 11.
I'd like to work on the fix for this, and add the failing inputs to cases.txt as the Contributing section asks.
- Langage dominant
- Python
- Étoiles
- 1
- Forks
- 6
- Merge moyen
- 23 h 30 min
- PR mergées (30 j)
- 20
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classPeut-être pris @tanujb03 l’a pris il y a 4 jours. Ouvertebug good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
techcsispit/code-corner#35 ·
Les mainteneurs répondent en général sous 1 jour
-
Failed compilations always report 0.000 secondsPeut-être pris @Nik-2208 l’a pris il y a 1 jour. Ouvertebug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
techcsispit/code-corner#37 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Add test cases to a problemPeut-être pris @25crns l’a pris il y a 11 jours. Ouvertegood first issue tests
techcsispit/code-corner#2 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de techcsispit/code-corner
Issues similaires
-
customer-reported question
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Azure/azure-sdk-for-python#49548 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
btclib-org/btclib-wallet#409 ·
Les mainteneurs répondent en général sous 1 jour
-
Phase 2 PSA Capability & Career Profile
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
fastmachinelearning/hls4ml#1582 ·
Les mainteneurs répondent en général sous 3 jours
-
Sort modelsOuverteenhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour